Reverse all string

Q. Write a C program to read a string from user and display string in reverse order.


Example:
User entered string: This is a good blog
Result/output: blog good a is This


Ans.


/*c program for reverse all string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
 char str[30];
 int i,tmp;
 printf("Enter any string: ");
 gets(str);
 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(" ");
 }
 getch();
 return 0;
}


/***************Output*****************/


Reverse all string C program output
Screen shot for reverse all string C program



Related Programs:

  1. Reverse all words but not string
  2. Reverse each first character of word & add extra word
  3. Change case of string(Toggle/Title Case)
  4. Display string vertically
  5. Search sub string from main string
  6. Search sub string individual from main string
  7. Position and repetition of character in string

Comments