I am new to programming.I have written this code which arranges the words in reverse order i.e.,
if input is "I Am Sad"
output should be "Sad Am I"
but am not able to get where i am going wrong
so plz help me.
here is the code
#include<stdio.h>
#include<string.h>
main()
{
char s[]="I Am Sad";
char str[10];int i;
char *st2;
char *st;
st=&s[0];
while(*st!='\0')
{
if(*st==' ')
st2=st;
*st++;
}
for(;strlen(str)!=strlen(s);)
{
*st2++;
st=st2;
for(i=0;(*st!='\0')&&(*st!=' ');*st++,i++)
str[i]=*st;
str[i]=' ';
for(;*st2!=' ';*st2--);
}
str[i]='\0';
puts(str);
}