elle


{ City } hyderabad
< Country > india
* Profession * student
User No # 48829
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 2
Users Marked my Answers as Wrong # 4
Questions / { elle }
Questions Answers Category Views Company eMail




Answers / { elle }

Question { ADP, 31194 }

"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

#include
#include
#include
#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