C Program Reverse all words not string | Reverse Words only from given String in C

C Program Reverse all words not string | Reverse Words only from given String in C | C assignment to reverse Word only

C program to accept a string from user and reverse all words but not string using pointer.



/*c program for reverse all words but not string using pointer*/

#include
#include
int main()
{
 char str[30];
 char *p,*tmp;
 printf(" Enter any string : \n");
 gets(str);
 for(p=str; *p!='\0'; p++)
 {
  if(*(p+1)==' ' || *(p+1)=='\0')
  {
   for(tmp=p; *tmp!=' ' && tmp>=str; tmp--)
     printf("%c",*tmp);
  }
  printf(" ");
 }
 getch();
 return 0;
}

OUTPUT :
Enter Any String : 
Life is Good


efiL si dooG

No comments:

Post a Comment