#include <iostream>
#include <stdlib.h>
using namespace std;
void main()
{
int i,j,begin,end;
char temp;
char str[] = "i come form helongjiang.";
i = 0;
j = strlen(str)-1; //因为数组从0开始,所以减1
printf("str = %s/n",str);
//1 先整个倒置
while(j>i)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
j--;
i++;
}
printf("str = %s/n",str);
//2 分段逆置
i = 0;
while(str[i]!=0)
{
if(str[i]!=' ')
{
begin = i;
while(str[i]!=0 && str[i]!=' ')
{
i++;
}
end = i-1;
}
while(begin<end)
{
temp = str[begin];
str[begin] = str[end];
str[end] = temp;
begin++;
end--;
}
}
printf("str = %s/n",str);
}