"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
WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..
What are the rules for identifiers in c?
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions
FILE PROGRAMMING
When c language was developed?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
In a byte, what is the maximum decimal number that you can accommodate?
How many levels of indirection in pointers can you have in a single declaration?
What is the use of function overloading in C?
Why we not create function inside function.
What is the use of a conditional inclusion statement in C?
What is the purpose of realloc()?
What is pointers in c with example?
What is scanf () in c?
What is non linear data structure in c?