#include <iostream>
#include <stdio.h>
int main()
{
int num = -12345,j=0,i=0,flag=0,begin,end;
char str[] = "this is a book",temp;
j = strlen(str) - 1;
printf("string = %s\n",str);
while(j>i)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
j--;
i++;
}
printf("string = %s\n",str);
i = 0;
while(str[i])
{
if(str[i] != ' ')
{
begin = i;
while(str[i]&&str[i] != ' ')
{
i++;
}
i = i-1;
end = i;
}
while(end>begin)
{
temp = str[begin];
str[begin] = str[end];
str[end] = temp;;
end--;
begin++;
}
i++;
}
printf("string = %s\n",str);
return 0;
}
这程序可以输出结果,第一步进行全部倒转,之后进行单词倒转实现结果,大家有没有更简便的一起交流一下