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

"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above

0 Answers  


How. To pass the entrance test

1 Answers   Tech Mahindra,


What does & mean in scanf?

0 Answers  


pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)

0 Answers   Subex,


Explain what is the use of a semicolon (;) at the end of every program statement?

0 Answers  


I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?

3 Answers  


WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER

0 Answers  


Are the outer parentheses in return statements really optional?

0 Answers  


What are local static variables?

0 Answers  


Which is best linux os?

0 Answers  


What is array of pointers to string?

0 Answers  


When should the register modifier be used? Does it really help?

0 Answers  


Categories