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 / vinod kumar
#include"stdio.h"
#include"stdlib.h"
int reverse(char *string, char delimiter)
{
char *src, *dest;
char *temp = string;
while( *temp )
{
if (*temp == delimiter)
{
temp++;
continue;
}
src=dest=temp;
while ( (*(dest+1) != delimiter) &&
( *(dest+1) != '\0' )) dest++;
//( *(dest+1) != '\n' ) &&
temp=dest+1;
while( dest > src )
{
char tmp = *dest;
//*dest -- = *src;
*dest = *dest-- *src;
//*src++=tmp;
*src = *src++ tmp;
}
}
return 0;
}
int main()
{
char name[] = "vinod kumar dhochak";
printf("%s\n",name);
reverse(name,' '); /* space as delimiter,Reverse Words
*/
printf("%s\n",name);
reverse(name,'\n'); /* Reverse Complete Sentence */
printf("%s\n",name);
}
| Is This Answer Correct ? | 5 Yes | 6 No |
Post New Answer View All Answers
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
write a program for area of circumference of shapes
Design an implement of the inputs functions for event mode
Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines
Write a program to model an exploding firecracker in the xy plane using a particle system
How to palindrom string in c language?
why nlogn is the lower limit of any sort algorithm?
can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail
how to test pierrot divisor
How can you relate the function with the structure? Explain with an appropriate example.
#include
Develop a routine to reflect an object about an arbitrarily selected plane
why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?
could you please send the program code for multiplying sparse matrix in c????
how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns