"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
How can I read and write comma-delimited text?
Explain what is the heap?
Explain what is the general form of a c program?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
What math functions are available for integers? For floating point?
Explain what happens if you free a pointer twice?
swap 2 numbers without using third variable?
Are pointers integers in c?
Explain how do you declare an array that will hold more than 64kb of data?
What is bss in c?
What is bubble sort in c?
What is volatile variable in c?
hi send me sample aptitude papers of cts?
How can you be sure that a program follows the ANSI C standard?
Why are all header files not declared in every c program?