Write a code to reverse string seperated by spaces
i/p str=India is my country
o/p str=aidnI si ym yrtnuoc
After writing code, optimize the code



Write a code to reverse string seperated by spaces i/p str=India is my country o/p str=aidnI si ym..

Answer / laju

#include<stdio.h>
#include<conio.h>
strrev(char *,char *);
void main()
{
clrscr();
char *p,*q;
char str[100];
printf("enter the string");
gets(str);
p=q=str;
while(*q!='\0')
{
if(*q==' ')
{
strrev(p,q-1);
p=q+1;

}
q++;


}

strrev(p,q-1);
puts(str);

getch();

}
strrev(char *p,char *q)
{
char temp;
while(q>p)
{
temp=*q;
*q=*p;
*p=temp;
q--;
p++;
}

}

Is This Answer Correct ?    4 Yes 3 No

Post New Answer

More C Interview Questions

Explain the advantages and disadvantages of macros.

0 Answers   TCS,


write a C code to reverse a string using a recursive function, without swapping or using an extra memory.

9 Answers   Motorola, TCS, Wipro,


program to locate string with in a string with using strstr function

2 Answers   Huawei, Shreyas,


What are c preprocessors?

0 Answers  


What are comments and how do you insert it in a C program?

0 Answers  






how we do lcm of two no using c simple if while or for statement

1 Answers  


What is property type c?

0 Answers  


What is getch() function?

0 Answers  


how to print a statement in c without use of console statement ,with the help of if statement it should print

2 Answers   Satyam,


What is wrong with this declaration?

0 Answers  


main() { int i; printf("%d",scanf"%d",&i))//if the input is 12 24 34 then wat will be the output }

2 Answers  


related proverb of "dont count your chicken before it hatches"

1 Answers  


Categories