C Program to accept a string and print each word in reverse

CWC
0 Min Read

C Program to accept a string and print each word in reverse

#include<conio.h>
#include<stdio.h>
main( )
{
char name[80];
int i,j,start=0,end,len;
clrscr( );
printf(“enter a string”);
scanf(“%s”,name);
for(i=0;i<80 &&((name[i]=getchar( ) )!=’\n’);i++);
len=i;
for(i=0;i<len;i++)
if(name[i]==’ ‘|| name[i]==’\n’)
{
end=i;
while((end--)>=start)
{
printf(“%c”,name[end]);
}
start=i+1;
}
getch( );
}

 

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version