Friday, June 1, 2012

Reverse all words but not string

Q. Write a C program to reverse all words but not string.
Let's assume string is: This Is A Good Blog
We wants to do: sihT sI A dooG golB


Ans.


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


/***************Output********************/
Output of reverse all words but not string C program
Screen shot for reverse words in string c program


Related Programs:

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

No comments:

Post a Comment