pgm in c to reverse string by word using array(god is love
becomes love is god)
(no additional array can used,space is only delimiter
between words )

Answer Posted / vaibhav srivastava

#include<stdio.h>

int main()
{
char str[50];
int i,j,k;
printf("\nEnter the string\t");
fflush(stdin);
gets(str);
puts(str);

for (i=0; str[i]!='\0';i++);
for ( k=i; k>0; k--)
{ if ( str[k]==' ' || k==i)
{ for( j=k-1; (str[j]!=' ') && (j!=-1) ;j--);
{
while ( ++j!=k)
{printf("%c", str[j]);}
printf(" ");


}


}


}

printf("\n");

}

Is This Answer Correct ?    22 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the scope of static variables in c language?

633


Explain threaded binary trees?

684


Write a program to swap two numbers without using the third variable?

601


Is r written in c?

728


What is null in c?

602






When can a far pointer be used?

593


What are the features of the c language?

650


Differentiate between Macro and ordinary definition.

734


hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .

1906


Can you think of a logic behind the game minesweeper.

2012


What are header files in c?

620


Can the sizeof operator be used to tell the size of an array passed to a function?

622


What will the code below print when it is executed?   int x = 3, y = 4;         if (x = 4)                 y = 5;         else                 y = 2;         printf ("x=%d, y=%d ",x,y);

1360


I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

566


What does volatile do?

569