Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   C coding (http://www.go4expert.com/forums/c-coding-t1459/)

sakthi.eeswari 22Sep2006 19:02

C coding
 
Hi ,
Can any one help me.I need the C coding for sort n number of names using pointers and functions in alphabetical order.plz help me.

-Sakthi

kingo 26Sep2006 10:27

Re: C coding
 
Code:

#include<string.h>
#include<stdio.h>
#include<stdlib.h>

void bubble(char *items, int count);

void main()
{
        char s[255];
        clrscr();
        printf("\nEnter a string : ");
        gets(s);
        bubble(s, strlen(s));
        printf("\nThe sorted string is : %s", s);
        getch();
}

void bubble(char *items, int count)
{
        int a, b;
        char t;

        for (a = 1; a < count; a++)
        for (b = count - 1; b >= a; b--)
        {
          if(items[b-1] > items[b])
          {
            t = items[b-1];
            items[b-1] = items[b];
            items[b] = t;
          }
        }
}



All times are GMT +5.5. The time now is 11:30.