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

who is the father of C Language?

20 Answers   CTS, UST,


What is a node in c?

0 Answers  


write a c program that prints all multiples of 3between 1 and 50.

5 Answers  


What are the advantages of Macro over function?

1 Answers  


You are given a string which contains some special characters. You also have set of special characters. You are given other string (call it as pattern string). Your job is to write a program to replace each special characters in given string by pattern string. You are not allowed to create new resulting string. You need to allocate some new memory to given existing string but constraint is you can only allocate memory one time. Allocate memory exactly what you need not more not less.

2 Answers   Microsoft,






What is the difference between #include and #include 'file' ?

0 Answers  


An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above

0 Answers  


How can I get Single byte from 'int' type variable? Can we alter single bit or multiple bits in int type variable? if so, How?

2 Answers  


The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?

0 Answers  


Why does the call char scanf work?

0 Answers  


What is void main () in c?

0 Answers  


Can a variable be both const and volatile?

0 Answers  


Categories