About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Tuesday, September 3, 2013

C Program to Reverse Letter in Each Word of the Entered String

In this program we are going to accept a string . This program will check for word inside string and if word founds then program will reverse that word. Similarly it will reverse out all all the words.
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
char str[]="Welcome to Programming World";
char str1[10];

int i=0,j=0;
clrscr();

while(str[i]!='')
{
 if(str[i]!=' ')
 {
 str1[j]=str[i];
 j++;
 }
 else
   {
   str1[j]='';
   printf("%s", strrev(str1));
   printf(" ");
   j=0;
   }
 i++;
}

   str1[j]='';
   printf("%s", strrev(str1));

getch();
}
Output :
emocleW ot gnimmargorP dlroW

Explanation of C Program :

Step 1 : Space Character Encountered
if(str[i]!=' ')
 {
 str1[j]=str[i];
 j++;
 }
Store Character into Another String Variable. As soon as Space character encounters then reverse the string and print the String.

No comments: