Monday, 6 February 2017

C program to reverse each word in given line of text

#include <stdio.h>
#include <string.h>
#include <conio.h>
main()
{
int i=0,j;
char name[50];
clrscr();
gets(name);
j=strlen(name)-1;
for(;j>=0;j--)
{
if(name[j] == ' ' || j == 0)
{
i=j;
do
{
printf("%c",name[i]);
i=i+1;

}while(name[i] != '\0' && name[i] != ' ');
printf("\t");
}
}
getch();
}

No comments:

Post a Comment