"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 are the disadvantages of c language?
What is a loop?
What is the difference between union and anonymous union?
Explain Function Pointer?
What is the difference between %d and %i?
GIVEN A FLOATING POINT NUMBER HOW IS IT ACTUALLY STORED IN MEMORY ? CAN ANYONE EXPLAIN?? THE 32 BIT REPRESENTATION OF A FLOATING POINT NUMBER ALLOTS: 1 BIT-SIGN 8 BITS-EXPONENT 23 BITS-MANTISSA
What are linker error?
The __________ attribute is used to announce variables based on definitions of columns in a table?
What is array of pointers to string?
What is the difference between #include and #include 'file' ?
What is the advantage of c?
write a program for the normal snake games find in most of the mobiles.
Explain the difference between malloc() and calloc() function?
my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?
Which is the best website to learn c programming?