无聊写了一个,请大牛指点
void ReverseWordList(char * str)
{
char * p = str;
char * start = str;
char * end = str;
bool inWord = false;
while(*end++);
end--;
Reverse(start, end);
while(*p)
{
if(*p==' ')
{
if(inWord)
{
inWord = false;
end = p-1;
Reverse(start, end);
}
}
else
{
if(!inWord)
{
inWord = true;
start = p;
}
}
p++;
}
if(inWord)
{
Reverse(start, p-1);
}
}
void Reverse(char * start, char * end)
{
while(start{
*start ^= *end;
*end ^= *start;
} *start++ ^= *end--;
}