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 / 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 multidimensional arrays

1064


What is meant by keywords in c?

1036


What is the purpose of sprintf?

1066


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

3183


What is dynamic memory allocation?

1283


What is array of pointers to string?

1000


Explain how do you declare an array that will hold more than 64kb of data?

1398


Explain the difference between malloc() and calloc() function?

988


Which is better between malloc and calloc?

1120


what is the function of pragma directive in c?

1061


What is difference between constant pointer and constant variable?

1204


What is typedef struct in c?

1000


what are the advantages of a macro over a function?

1096


What is LINKED LIST? How can you access the last element in a linked list?

1019


Combinations of fibanocci prime series

1555