Reverse a string word by word??

Answer Posted / rohit_kamlakar

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int length,i,j;
char string[500];clrscr();
printf("Enter the string=");
gets(string);
length=strlen(string); int y=length,z=0;
for(i=length-1;i>=0;i--)
{
if(int(string[i])==32)
{ printf(" ");
for(j=i+1;j<length;j++)
{
printf("%c",string[j]);
z++;
}
length=y-z;
}

if(i==0)
{ j=i; printf(" ");
while(int(string[j])!=32)
{
printf("%c",string[j]);

j++;
}
}

}
getch();
}

Is This Answer Correct ?    3 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what are # pragma staments?

1619


Is it possible to use curly brackets ({}) to enclose single line code in c program?

782


What is an array in c?

584


Why does everyone say not to use scanf? What should I use instead?

676


How do you sort filenames in a directory?

699






What are the types of c language?

547


What is strcmp in c?

592


What is the size of structure pointer in c?

605


can we have joblib in a proc ?

1650


What is difference between constant pointer and constant variable?

618


What is variable declaration and definition in c?

493


Did c have any year 2000 problems?

647


program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)

1616


Explain what are the advantages and disadvantages of a heap?

589


Why is c called c?

618