```
void reverseWords(char *s)
{
if (!s && *s == 0)
return;
char *start;
for (start = s; *start == ' '; ++start);
if (*start == 0)
{
*s = 0;
return;
}
char *end;
for (end = s + strlen(s) - 1; *end == ' '; --end);
char ch;
char *i, *j;
for (i = start, j = end; i < j; ++i, --j)
{
ch = *i;
*i = *j;
*j = ch;
}
char *next_i;
for (i = start; i <= end;)
{
for (j = i + 1; j <= end && *j != ' '; ++j);
next_i = j + 1;
for (j = j - 1; i < j; ++i, --j)
{
ch = *i;
*i = *j;
*j = ch;
}
i = next_i;
}
for (i = start, j = s; i <= end; ++i, ++j)
*j = *i;
*j = 0;
}
```