如 将字符串 "Do or do not, there is no try."
转换为 "try. no is there not,do or Do"
int ReverseWords(char str[])
{
char *buffer;
int tokenReadPos, wordReadPos, wordEnd, writePos = 0;
tokenReadPos = strlen(str)-1;
buffer = (char*)malloc(tokenReadPos+2);
if(!buffer)
return;
while(tokenReadPos>=0)
{
if(str[tokenReadPos] == '')
{
buffer[writePos++] = str[tokenReadPos--];
}
else
{
wordEnd = tokenReadPos;
while(tokenReadPos>=0 && str[tokenReadPos]!='')
{
tokenReadPos--;
}
wordReadPos = tokenReadPos+1;
while(wordReadPos<=wordEnd)
{
buffer[writePos++] = str[wordReadPos++];
}
}
}
buffer[writePos]='\0';
strcpy(str, buffer);
free(buffer);
return 1;
}