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
write an algorithm to display a square matrix.
Write a program with dynamically allocation of variable.
What is the scope of static variable in c?
Explain how does free() know explain how much memory to release?
Write a program of prime number using recursion.
Explain data types & how many data types supported by c?
What is C language ?
Do you know the difference between malloc() and calloc() function?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
What does typedef struct mean?
What is the difference between array_name and &array_name?
Do you know the purpose of 'register' keyword?
Write the syntax and purpose of a switch statement in C.
What are the 4 types of unions?
Is void a keyword in c?