C coding

Discussion in 'C' started by sakthi.eeswari, Sep 22, 2006.

  1. sakthi.eeswari

    sakthi.eeswari New Member

    Joined:
    Sep 13, 2006
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. kingo

    kingo New Member

    Joined:
    Aug 30, 2006
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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;
    	   }
    	}
    }
     
    Last edited by a moderator: Sep 26, 2006

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice