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:
Post a Comment