标签:ring ever 一个 字符数组 return 个数 rev str temp
有一个字符数组的内容为:"i am a student",#include<stdio.h>
#include<string.h>
int MyStrlen(char *str)
{
int count = 0;
while (*str != ‘\0‘)
{
str++;
count++;
}
return count;
}
void Reverse(char *left, char *right)
{
char temp;
while (left < right)
{
temp = *left;
*left = *right;
*right = temp;
left++;
right--;
}
}
void ReverseSentence(char *str)
{
char *left = str;
char *right = str + MyStrlen(str) - 1;
char *p=str;
Reverse(left,right);
while (*p != ‘\0‘)
{
char *b = p;
while (*p != ‘ ‘&&*p != ‘\0‘)
{
p++;
}
Reverse(b, p-1);
if (*p==‘ ‘)
{
p++;
}
}
}
int main()
{
char str[] = "i am a student";
ReverseSentence(str);
printf("%s\n",str);
system("pause");
return 0;
}
c语言的灵魂》》》指针
字符数组为:"i am a student",将数组改为"student a am i
标签:ring ever 一个 字符数组 return 个数 rev str temp
原文地址:https://blog.51cto.com/14233078/2380945