"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 / elle
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define MAX 20 //define size
int main()
{
int len,j=0;
char *p, *line[MAX],*q;
p=(char *)malloc(MAX);
char *l="i love my country";
int i=0;
while(*l!='\0')
{
if(*l==' ')
//whenever a space is encountered, copy the string q into
//the array
{
*p='\0';
line[i]=(char *)malloc(MAX);
strcpy(line[i],q);
strcpy(p,"");
l++;
i++;
j=0;
}
else
{
if(j==0)
{
q=p;
}
*p=*l;
l++;
p++;
j++;
}
}
*p='\0';
line[i]=(char *)malloc(MAX);
strcpy(line[i],q);
printf("printing in reverse\n");
while(i>=0)
{
printf("%s ",line[i]);
i--;
}
}
| Is This Answer Correct ? | 2 Yes | 4 No |
Post New Answer View All Answers
What is the use of pointers in C?
A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?
Explain what is page thrashing?
Which node is more powerful and can handle local information processing or graphics processing?
What is the purpose of scanf() and printf() functions?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list
Can the curly brackets { } be used to enclose a single line of code?
What are bitwise shift operators in c programming?
What is a pointer on a pointer in c programming language?
What are volatile variables in c?
Which of these functions is safer to use : fgets(), gets()? Why?
What are the rules for the identifier?
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
What are compound statements?