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 / 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 |
How do you define a string?
How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls answer it.. Thanks in Advance
How to implement call back functions ?
How can you avoid including a header more than once?
What does the error message "DGROUP exceeds 64K" mean?
If fflush wont work, what can I use to flush input?
write a program in c language to print your bio-data on the screen by using functions.
6 Answers College School Exams Tests, IBM,
Why is it important to memset a variable, immediately after allocating memory to it ?
what is recursion in C
What are identifiers and keywords in c?
write a program to check whether a given integer is a strong number or not? [Hint: 145=1!+4!+5! =1+24+120 =145]
What is the benefit of using #define to declare a constant?