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
Explain how can I manipulate strings of multibyte characters?
Linked list is a Linear or non linear explain if linear how it working as a non linear data structures
What does main () mean in c?
explain what is an endless loop?
The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration
Can you write the function prototype, definition and mention the other requirements.
How do I determine whether a character is numeric, alphabetic, and so on?
How to compare array with pointer in c?
What is the right type to use for boolean values in c?
Write a program to show the change in position of a cursor using c
Subtract Two Number Without Using Subtraction Operator
What are extern variables in c?
Explain how can I convert a number to a string?
What are the uses of a pointer?
How does free() know explain how much memory to release?