"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

What is strcpy() function?

650


Can include files be nested?

619


to find the closest pair

1815


Why do we use null pointer?

599


how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.

1207






Why is c platform dependent?

610


State the difference between realloc and free.

620


What is function prototype?

603


i have a written test for microland please give me test pattern

2173


What is the difference between procedural and functional programming?

512


What is the value of c?

563


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

627


What is sizeof int?

629


What is floating point constants?

678


Write a program to reverse a given number in c language?

608