The process can be as simple or complex as you'd like. For instance, a simpler but more difficult to understand method would be to use two pointers and walk down the string. When the end pointer finds a space or the end of the string, reverse from the start pointer to the end pointer and assign the end pointer to the start pointer. Lather, rinse, repeat.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
static void revstr ( char *start, char *end )
{
char hold;
while ( start < end ) {
hold = *start;
*start = *end;
*end = hold;
start++;
end--;
}
}
int main ( void )
{
char buf[] = "Hello world haha";
char *last = buf + sizeof buf;
char *start = buf;
char *end;
for ( end = start; end != last; start = ++end ) {
while ( *end != '\0' && !isspace ( *end ) )
end++;
revstr ( start, end - 1 );
}
printf ( "%s\n", buf );
return 0;
}
-Prelude