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 |
who is the father of C Language?
20 Answers CTS, UST,
What is a node in c?
write a c program that prints all multiples of 3between 1 and 50.
What are the advantages of Macro over function?
You are given a string which contains some special characters. You also have set of special characters. You are given other string (call it as pattern string). Your job is to write a program to replace each special characters in given string by pattern string. You are not allowed to create new resulting string. You need to allocate some new memory to given existing string but constraint is you can only allocate memory one time. Allocate memory exactly what you need not more not less.
What is the difference between #include and #include 'file' ?
An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above
How can I get Single byte from 'int' type variable? Can we alter single bit or multiple bits in int type variable? if so, How?
The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?
Why does the call char scanf work?
What is void main () in c?
Can a variable be both const and volatile?