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

Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me

0 Answers  


What are the different types of data structures in c?

0 Answers  


write a program to print largest number of each row of a 2D array

0 Answers  


What is difference between && and & in c?

0 Answers  


how to introdu5ce my self in serco

0 Answers  






how should functions be apportioned among source files?

0 Answers  


Write a program to produce the following output in c language? 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

2 Answers  


How to print all the 26 alphabets in this order in C. AbCdEfGh..... it should print dynamically from a to z and do not print this using pgm like this print("Ab......"); Use loops or anything to print all alphabets

2 Answers   Hexaware,


How to reverse a string using a recursive function, with swapping?

5 Answers  


What is array of structure in c?

0 Answers  


What is ambagious result in C? explain with an example.

0 Answers   Infosys,


#include<stdio.h> main() { int i=5; printf("%d",i*i-- - --i*i*i++ + ++i); } tell the answer with correct reason .specially reason is important nt answer ans by turbo c is -39

1 Answers   GameLoft,


Categories