#include <iostream>
using namespace std;
void ReverseWord(char* pBegin, char* pEnd)
{
while(pBegin < pEnd)
{
char temp = *pBegin;
*pBegin = *pEnd;
*pEnd = temp;
pBegin++;
pEnd--;
}
}
void ReverseSentence(char *str)
{
char *p = str;
char *q = str;
while(*q!='\0')
{
if(*q == ' ')
{
ReverseWord(p, q-1);
q++;
p = q;
}
else
q++;
}
ReverseWord(p, q-1);//翻转最后一个单词
ReverseWord(str,q-1);//
}
int main()
{
char str[] = "I come from Nanjing.";
ReverseSentence(str);
cout<<str<<endl;
return 0;
}