"I LOVE MY COUNTRY"
write a c program to get "COUNTRY MY LOVE I" as the output.
Use any other programming language. It is not mandatory to
use C.
Answer Posted / sandeep
#include <stdio.h>
void rev(char *l, char *r);
int main(int argc, char *argv[])
{
char buf[] = "I LOVE MY COUNTRY";
char *end, *x, *y;
// Reverse the whole sentence first..
for(end=buf; *end; end++);
rev(buf,end-1);
// Now swap each word within sentence...
x = buf-1;
y = buf;
while(x++ < end)
{
if(*x == '\0' || *x == ' ')
{
rev(y,x-1);
y = x+1;
}
}
// Now print the final string....
printf("%s\n",buf);
return(0);
}
// Function to reverse a string in place...
void rev(char *l,char *r)
{
char t;
while(l < r)
{
t = *l;
*l++ = *r;
*r-- = t;
}
}
| Is This Answer Correct ? | 35 Yes | 17 No |
Post New Answer View All Answers
the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function
What is data types?
What does the c preprocessor do?
In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping
What is selection sort in c?
What happens if a header file is included twice?
Explain what happens if you free a pointer twice?
What does a pointer variable always consist of?
Why we use conio h in c?
What is variable declaration and definition in c?
how is the examination pattern?
I have a varargs function which accepts a float parameter?
What should malloc() do?
Why array is used in c?
What is %lu in c?