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
In C, What is the #line used for?
Explain enumerated types in c language?
Is it acceptable to declare/define a variable in a c header?
What is spark map function?
What are the restrictions of a modulus operator?
Why does everyone say not to use gets?
Why is c called a mid-level programming language?
can anyone please tell about the nested interrupts?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
Describe the steps to insert data into a singly linked list.
Why do we use return in c?
what is bit rate & baud rate? plz give wave forms
What does p mean in physics?
What are the two types of functions in c?
what is the structure pointer?