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

What is a example of a variable?

748


How do you convert strings to numbers in C?

918


What is the difference between test design and test case design?

1801


Why is main function so important?

830


why wipro wase

2035


What is difference between far and near pointers?

789


Explain what is a static function?

833


What are the types of pointers?

775


What is the use of sizeof?

748


What does the characters “r” and “w” mean when writing programs that will make use of files?

1167


What is c++ used for today?

863


What does int main () mean?

755


what is the different bitween abap and abap-hr?

1921


What is multidimensional arrays

836


What are register variables in c?

783