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 )

Answers were Sorted based on User's Feedback



pgm in c to reverse string by word using array(god is love becomes love is god) (no additional a..

Answer / 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

pgm in c to reverse string by word using array(god is love becomes love is god) (no additional a..

Answer / charan

#include <stdio.h>
#include <conio.h>
void main()
{
char *str;
char s[10][10];
int i=0,j=0,p=0;
clrscr();
printf("Enter the string");
gets(str);
while(str)
{
if(str[i]!=' ')
s[j][p++]=str[i];
else
{
s[j][p++]='\0';
p=0;
}
i++;
}
for(i=j;i>=0;i--)
puts(s[i]);
getch();
}

Is This Answer Correct ?    1 Yes 10 No

Post New Answer

More C Interview Questions

Does free set pointer to null?

0 Answers  


What is c variable?

0 Answers  


create a C program that displays one z,two y's,three x's until twenty six A's. plzz answer i need it tomorrow.

4 Answers  


a simple c program using 'for' loop to display the output 5 4 3 2 1

2 Answers   Google,


How to access or modify the const variable in c ?

16 Answers   HCL, HP,






find the size of structure without using the size of function

1 Answers   Bosch,


O,T,T,F,F,S,S,E,N,?,?,?,T,F,F,S,S,E,N

9 Answers   ADP,


What is a stream water?

0 Answers  


What are linker error?

0 Answers  


char S; char S[6]= " HELLO"; printf("%s ",S[6]); output of the above program ? (0, ASCII 0, I,unpredictable)

7 Answers   Mascot,


Here is a neat trick for checking whether two strings are equal

0 Answers  


how to add numbers without using arithmetic operators.

14 Answers   TCS,


Categories