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
A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream
Explain how do you print an address?
What is ponter?
What are the 4 types of functions?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What is an array? What the different types of arrays in c?
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
how to make a scientific calculater ?
What is the use of putchar function?
What is the difference between volatile and const volatile?
#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} wat would be the output??
Compare interpreters and compilers.
write a program to find out prime number using sieve case?
What is c++ used for today?