String in Reverse Order – C Program

Display String in Reverse Order – C Program

write a c program to get string from user and display string in reverse order.

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

void main()
{
 char str[30];
 int i,tmp;
 printf("Enter the string =");
 gets(str);

printf("The reverse string = ");
 for(i=0; str[i]!='\0'; i++);
 for(i--; i>=0;i--)
 {
  if(str[i-1]==' ' || i==0)
  {
     for(tmp=i; str[tmp]!='\0' && str[tmp]!=' '; tmp++)
       {
          printf("%c",str[tmp]);
       }  
  }
  printf(" ");
 }

}

The output is reverse string program is :

Enter the string = My Name is Meera

The reverse string = Meera is Name My

 

Leave a Reply

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