Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

4341


write a program for area of circumference of shapes

2507


Design an implement of the inputs functions for event mode

3453


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

3472


Write a program to model an exploding firecracker in the xy plane using a particle system

4093


How to palindrom string in c language?

10815


why nlogn is the lower limit of any sort algorithm?

2787


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

2895


how to test pierrot divisor

2715


How can you relate the function with the structure? Explain with an appropriate example.

3388


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1572


Develop a routine to reflect an object about an arbitrarily selected plane

3553


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 ?

2720


could you please send the program code for multiplying sparse matrix in c????

3524


how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

3597