Trying to learn C and so I want to reverse each word in string. "Hello World" to "olleH dlroW" This is what I have so far.
int main()
{
char str[100];
int i;
printf("Enter string:");
fgets(str,sizeof(str),stdin);
for (i = 0; i <= strlen(str); i++)
{
if (str[i] == ' ')
{
// Here the space and how should I switch words now?
}
}
return 0;
}
Should I do something like this:
temp = str[i]; j = str[i-1];
and then switch places? str[i]=j; and j=temp; I am stuck at this point here!