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

What are the different types of C instructions?

0 Answers   InterGraph,


Between macros and functions,which is better to use and why?

0 Answers  


The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference

0 Answers  


Can we add pointers together?

0 Answers  


Multiply an Integer Number by 2 Without Using Multiplication Operator

0 Answers  






Program to find larger of the two numbers without using if-else,while,for,switch

11 Answers   iNautix, Wipro,


Explain how do you list files in a directory?

0 Answers  


whether itis a structured language?

1 Answers   Microsoft,


a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

0 Answers   Wilco,


diff .between strcture and union

2 Answers  


write a program to display the numbers having digit 9 in the given range from 1 to 100

1 Answers  


How do you print an address?

0 Answers   TCS,


Categories