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

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 )

2 Answers   Persistent,


to convert a string without using decrement operater and string functions

1 Answers  


There are N egg baskets and the number of eggs in each basket is a known quantity. Two players take turns to remove these eggs from the baskets. On each turn, a player must remove at least one egg, and may remove any number of eggs provided they all belong to the same basket. The player picking the last egg(s) wins the game. If you are allowed to decide who is going to start first, what mathematical function would you use to decide so that you end up on the winning side?

8 Answers   Google,


write a program to check whether a given integer is a strong number or not? [Hint: 145=1!+4!+5! =1+24+120 =145]

7 Answers  


What is meant by recursion?

0 Answers   ADP,


What is the best style for code layout in c?

0 Answers  


What is a structure member in c?

0 Answers  


How to write in a function declaration and in function call in which the function has 'n' number of varible or arguments?

2 Answers  


program to find a smallest number in an array

15 Answers   Microsoft, Sony,


In c programming language, how many parameters can be passed to a function ?

0 Answers  


Can a void pointer point to a function?

0 Answers  


a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

0 Answers  


Categories