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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a local variable be volatile in c?

571


What is c preprocessor mean?

775


What is the best way of making my program efficient?

559


Why doesnt this code work?

609


How many levels deep can include files be nested?

642






Explain how do you determine the length of a string value that was stored in a variable?

661


What is main () in c?

580


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

1452


What is the scope of static variable in c?

521


What are the types of pointers in c?

524


What is c system32 taskhostw exe?

578


Explain what are multibyte characters?

616


Explain how can you tell whether two strings are the same?

578


What is the use of typedef in structure in c?

534


which type of aspect you want from the student.

1695