I want to make a string to reverse the words but remain the words position the same.. (if input is "Hello world haha", the output should be "olleH dlrow ahah"), what should I do.. can I use the recursive method.. but how.. here is what I have done...
Code:
#include <stdio.h>
void revstr (char str[]);
main()
{
char str[100];
printf ("Enter the String :");
gets (str);
revstr (str);
return 0;
}
void revstr (char str[])
{
int i=0, j, k;
char word[50], reverse[50];
for (i=0; str[i]!='\0'; i++)
{
while (str[i]!=' ')
{
word[i]= str[i];
word[i+1]='\0';
}
for (j=i, k=0; (j>=0) || (str[j]=' '); j--, k++)
{
reverse[k] = word[j];
word[j] = '\0';
reverse[k+1] = ' ';
reverse[k+2] = '\0';
}
puts (reverse);
}
}
What I did is to iniciate word array to store words reverse array to reverse the letters, and put out the reverse array string by string.. it seem to be the stupidest way to do so...