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 an array? What the different types of arrays in c?

646


What is variables in c?

596


What is the difference between local variable and global variable in c?

677


Write a program to know whether the input number is an armstrong number.

660


Why do we need functions in c?

541






Write a C program linear.c that creates a sequence of processes with a given length. By sequence it is meant that each created process has exactly one child. Let's look at some example outputs for the program. Here the entire process sequence consists of process 18181: Sara@dell:~/OSSS$ ./linear 1 Creating process sequence of length 1. 18181 begins the sequence. An example for a sequence of length three: Sara@dell:~/OSSS$ ./linear 3 Creating process sequence of length 3. 18233 begins the sequence. 18234 is child of 18233 18235 is child of 18234 ........ this is coad .... BUt i could not compleate it .....:( #include #include #include #include int main(int argc, char *argv[]) { int N; pid_t pid; int cont; if (argc != 2) { printf("Wrong number of command-line parameters!\n"); return 1; } N = atoi(argv[1]); printf("Creating process sequence of length %d.\n",N); printf("%d begins the sequence.\n",getpid()); /* What I have to do next ?????? */ }

1609


What is meant by preprocessor in c?

524


Where we use clrscr in c?

686


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

1775


The statement, int(*x[]) () what does in indicate?

635


What do you mean by recursion in c?

615


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

925


Explain the use of fflush() function?

614


What is the value of c?

560


Why is c called "mother" language?

849