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

write an algorithm to display a square matrix.

2223


Write a program with dynamically allocation of variable.

603


What is the scope of static variable in c?

535


Explain how does free() know explain how much memory to release?

575


Write a program of prime number using recursion.

619






Explain data types & how many data types supported by c?

586


What is C language ?

1530


Do you know the difference between malloc() and calloc() function?

614


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3124


What does typedef struct mean?

661


What is the difference between array_name and &array_name?

778


Do you know the purpose of 'register' keyword?

642


Write the syntax and purpose of a switch statement in C.

628


What are the 4 types of unions?

609


Is void a keyword in c?

578