Pages

Subscribe:

String Sorting Using C

String sorting c program  compare words alphabetically . Easy sorting method used in this program.

Program :

/* STRING SORT */
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define ITEMS 5         /* defines preprocessor macro */
#define MAXCHAR 20

void main()
{
char st[ITEMS][MAXCHAR],dummy[MAXCHAR];
int i=0,j=0;
clrscr();
    printf("\n\t Enter names %d items \n",ITEMS);
    while(i<ITEMS)
    {
        scanf("\t%s",&st[i++]);
    }
    for(i=0;i<ITEMS-1;i++)
    {
        for(j=i+1;j<ITEMS;j++)
        {
           if(strcmp(st[i],st[j])>0)
           {
            strcpy(dummy,st[i]);
            strcpy(st[i],st[j]);
            strcpy(st[j],dummy);

           }

        }
    }
    printf(" \n\t Alphabetiacl list\n");
    for(i=0;i<ITEMS;i++)
    {

        printf("\t%s \n",st[i]);

    }
getch();
exit(0);
}

Output :






comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.