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

In a switch statement, explain what will happen if a break statement is omitted?

0 Answers  


What is a rvalue?

0 Answers   Global Logic,


plssssss help !!....using array.. turbo c.. create a program that will accept number of words to be consored. .a word must not exceed 10 characters long .the text to be entered will be no longer than 200 characters .there will be no 10 words example: enter number of words to be censor: 5 enter words to censor: windows office microsoft bill gates enter text to censor: bill gates founded microsoft and makes office and windows sample output: <consored> <censored> founded <censored> and makes <censored> and <censored>

1 Answers  


What is false about the following A compound statement is a.A set of simple statments b.Demarcated on either side by curly brackets c.Can be used in place of simple statement d.A C function is not a compound statement.

5 Answers   CCEM, TCS,


write a program to display all prime numbers

0 Answers  






Why c is called object oriented language?

0 Answers  


Did c have any year 2000 problems?

0 Answers  


i want to have a program to read a string and print the frequency of each character and it should work in turbo c

3 Answers   Persistent, Wipro,


Can static variables be declared in a header file?

0 Answers  


Explain how do you list files in a directory?

0 Answers  


What is the diffences between Windows XP and Windows Visa

1 Answers   Aricent, FHF,


Explain the use of bit fieild.

0 Answers  


Categories