See this simple program where I am managing the boundary and just reversing the characters within the boundary and it works
#include <stdio.h>
void reverse(char *begin, char *end)
{
char temp;
while (begin < end)
{
temp = *begin;
*begin++ = *end;
*end-- = temp;
}
}
void reverseWords(char *s)
{
char *word_begin = s;
char *temp = s;
while( *temp )
{
temp++;
if (*temp == '\0')
{
return;
}
else if(*temp == ' ')
{
reverse(word_begin, temp-1);
word_begin = temp+1;
}
}
}
main()
{
char words[] = "this is a test";
reverseWords(words);
printf("%s\n", words);
}