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
How many identifiers are there in c?
Explain the difference between ++u and u++?
What is an example of structure?
Can you assign a different address to an array tag?
Where static variables are stored in c?
Is multithreading possible in c?
How to write a code for reverse of string without using string functions?
What is dangling pointer in c?
Explain what is a stream?
What is the use of pointers in C?
What is int main () in c?
What are the differences between Structures and Arrays?
Explain a pre-processor and its advantages.
Can we assign string to char pointer?
Can an array be an Ivalue?