You need to account for the fact that there will not be a space after the last world. You could probably work the main loop so that the if(space == 0) stuff isn't needed.
Also:
Code:
for(lastindex;lastindex<(i/2);lastindex++)
Is probably not what you want. You want to swap characters from lastindex to i. But that conditional isn't right. What if I had a string of length 50, with lastindex equal to 44 at this point in the code? i must be > 44, so 44 / 2 = 22, which isn't greater than 44. The loop never runs, and characters are never swapped.
Your small inner for() loop makes my head hurt... let's reword it to use an offset variable:
Code:
for(offset = 0; offset = (i - lastindex) / 2; offset++)
swap(s[lastindex + offset], s[i - 1 - offset]);
Merging that into your function I get this, which works for me:
Code:
void PrintWordsReverse(char s[])
{
int N = strlen(s);
int count = 0, lastindex = 0, spaces = 0, offset;
for(int i = 0; i <= N; ++i)
{
if(s[i] == ' ' || s[i] == 0)
{
for(offset = 0; offset < (i - lastindex) / 2; ++offset)
swap(s[lastindex + offset], s[i - 1 - offset]);
lastindex = i + 1;
}
}
cout << s << endl;
}