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
What is a example of a variable?
How do you convert strings to numbers in C?
What is the difference between test design and test case design?
Why is main function so important?
why wipro wase
What is difference between far and near pointers?
Explain what is a static function?
What are the types of pointers?
What is the use of sizeof?
What does the characters “r” and “w” mean when writing programs that will make use of files?
What is c++ used for today?
What does int main () mean?
what is the different bitween abap and abap-hr?
What is multidimensional arrays
What are register variables in c?