I have this program
#include <stdio.h>
#include <stdlib.h>
int main()
{
char text[30];
int i,j,n;
puts("Enter the Text:");
gets(text);
n=strlen(text);
for(i=n;i>=0;i--)
{
if(text[i-1]==' '||text[i-1]==NULL )
{
for(j=i;text[j]!=' ';j++)
{
printf("%c",text[j]);
}
}
printf(" ");
}
getche();
}
Suppose if i input is "I am Happy" then my output is "Happy am I"
I am not sure where i went wrong in this program, i am not getting all the words , I am getting result as "happy [=w am " .Please programmers help me.
Thanks In Advance.
i have found the answer , thanks for your helps, Below is my code
#include <stdio.h>
#include <stdlib.h>
int main()
{
char text[100];
int i,j;
puts("Enter the Text:");
gets(text);
strrev(text);
for(i=0;text[i]!='\0';i++)
{
if(text[i+1]==' ' || text[i+1]==NULL)
{
for(j=i;j>=0 && text[j]!=' ';j--)
printf("%c",text[j]);
}
printf(" ");
}
getche();
}