"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
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
Explain what is meant by high-order and low-order bytes?
write a c program to find the sum of five entered numbers using an array named number
What are the types of i/o functions?
What 'lex' does?
How can I pad a string to a known length?
Explain how to reverse singly link list.
what are the 10 different models of writing an addition program in C language?
Explain what are preprocessor directives?
Can we declare function inside main?
Explain how do you convert strings to numbers in c?
What is the difference between int main and void main?
How reliable are floating-point comparisons?
Write a code to remove duplicates in a string.
What are the various types of control structures in programming?