"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
what are bit fields? What is the use of bit fields in a structure declaration?
What is a program?
Explain the use of fflush() function?
What is 1d array in c?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
How are pointers declared in c?
any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above
any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above
Why is c so popular?
Is c language still used?
How can I automatically locate a programs configuration files in the same directory as the executable?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
main() { printf("hello"); fork(); }
What is typedef struct in c?
How the c program is executed?