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

write a c program to print a given number as odd or even without using loop statements,(no if ,while etc)

10 Answers  


write a progam to display the factors of a given number and disply how many prime numbers are there?

2 Answers  


What are different types of variables in c?

0 Answers  


How can a program be made to print the name of a source file where an error occurs?

0 Answers  


How do I declare a pointer to an array?

6 Answers   IBM,






Without using main fn and semicolon,print remainder for a given number in C language

2 Answers  


while initialization of two dimensional arrays we can initialize like a[][2] but why not a[2][] is there any reason behind this?

4 Answers   Aptech,


What is else if ladder?

0 Answers  


1)what are limitations for recursive function? 2)write a program to read a text file and count the number of characters in the text file

1 Answers  


What is the difference between big endian form and little endian form? write a code to convert big endian form to little endian and vice versa..

5 Answers   Aricent, TCS,


what is reason of your company position's in india no. 1.

0 Answers   Accenture, TCS,


What is a Genralised LInked List?? Please give a detailed explation of it..

1 Answers  


Categories