Given an array of characters which form a sentence of
words, give an efficient algorithm to reverse the order of
the words (not characters) in it?

Answer Posted / tarak

#include<stdio.h>
int main()
{
char *p="i am working in TechM";
char *s,*temp;
char a[20];
int i=0;
s=p;
while(*p != '\0')
p++;
while(s != p){
while(*(--p)!=' ');
temp=p;
p++;
while(*p != '\0' && *p != ' ')
{
a[i++]=*p;
p++;
}
a[i++]=' ';
p=temp;
p--;
}
while(*s != ' ')
a[i++]=*s++;
a[i] = '\0';
printf("%s \n",a);
}
~

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In c programming language, how many parameters can be passed to a function ?

637


What is static identifier?

706


‎How to define structures? · ‎

636


What is #include stdlib h?

620


Write a program to swap two numbers without using the third variable?

604






Write a program to check palindrome number in c programming?

601


Why is c called a structured programming language?

686


in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

7413


Is using exit() the same as using return?

684


What is masking?

641


List out few of the applications that make use of Multilinked Structures?

1310


What is the correct declaration of main?

682


What is wrong with this initialization?

597


Here is a good puzzle: how do you write a program which produces its own source code as output?

602


What is time null in c?

587