#include
int main(void)
{
int i,j;
int wordstart = -1;
int wordend = -1;
char words[]= \"this is a test\";
char temp;
// Reverse each word
if(words[i] != ' ')
wordstart = i;
This statement what about the else part? if words[i] == ' ', and wordstart remains -1. So maybe try to use:
while (words[i] && words[i] == ' ') ++i;
if (!words[i])
break;
wordstart = i;
Then you should output the result out of the i loop. Finally, if you want to get the result you expected, you should reverse the whole sentence once more, with the way you used in the loop.