"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


Please Help Members By Posting Answers For Below Questions

which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

1421


Explain what is meant by high-order and low-order bytes?

637


write a c program to find the sum of five entered numbers using an array named number

1621


What are the types of i/o functions?

685


What 'lex' does?

722






How can I pad a string to a known length?

614


Explain how to reverse singly link list.

609


what are the 10 different models of writing an addition program in C language?

1443


Explain what are preprocessor directives?

631


Can we declare function inside main?

572


Explain how do you convert strings to numbers in c?

598


What is the difference between int main and void main?

578


How reliable are floating-point comparisons?

632


Write a code to remove duplicates in a string.

633


What are the various types of control structures in programming?

630