Program to accept a string and print each word in reverse - 100 Most Important C# Programs

90. Program to accept a string and print each word in reverse

Code:

#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( );

}