Reverse only Character not String – C Program

Reverse only Character but not String – C Program

write a c program to display all word in reverse order but not all string.

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
 char str[100];
 int i,temp;
 printf("Enter the string = ");
 gets(str);
 printf("The Reverse string = ");
 for(i=0; str[i]!=NULL; i++)
 {
  if(str[i+1]==' ' || str[i+1]==NULL)
  {
   for(temp=i; temp>=0 && str[temp]!=' '; temp--)
     {  
        printf("%c", str[temp]);
     }  
   }
  printf(" ");
 }
 getch();

}

The Reverse string program output is :

Enter the string = My Name is Meera

The Reverse string = yM emaN si areeM

 

Author: Meera Academy

Leave a Reply

Your email address will not be published. Required fields are marked *