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
Can a local variable be volatile in c?
What is c preprocessor mean?
What is the best way of making my program efficient?
Why doesnt this code work?
How many levels deep can include files be nested?
Explain how do you determine the length of a string value that was stored in a variable?
What is main () in c?
Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me
What is the scope of static variable in c?
What are the types of pointers in c?
What is c system32 taskhostw exe?
Explain what are multibyte characters?
Explain how can you tell whether two strings are the same?
What is the use of typedef in structure in c?
which type of aspect you want from the student.