Saturday, April 5, 2014

Program in C to sort all words of text in alphabatical order.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<conio.h>
void sort_string(char*);
 int main()
{
   char string[100];
   clrscr();
   printf("Enter some text\n");
   gets(string);

   sort_string(string);
   printf("%s\n", string);
   getch();
   return 0;

}

void sort_string(char *s)
{
   int c, d = 0, length;
   char *pointer, *result, ch;

   length = strlen(s);

   result = (char*)malloc(length+1);

   pointer = s;

   for(ch='a';ch<='z';ch++ )
   {
      for(c=0;c<length;c++ )
      {
         if(*pointer == ch )
         {
            *(result+d) = *pointer;
            d++;
         }
         pointer++;
      }
      pointer = s;
   }
   *(result+d) = '\0';
   strcpy(s, result);
   free(result);
}
Click here for more programs on C++

No comments:

Post a Comment

Program to develop for cost saving in hotel industry

 To develop a program for cost-saving in a hotel, you can consider the following features: Key Features 1. *Room Management*: Optimize room ...