Loading

C Program to Sort Names in Alphabetical Order

 C Program to Sort Names in Alphabetical Order


#include < stdio.h >
#include < conio.h >
#include < alloc.h >

void main()
{
    char *list[100],temp[10];
    int n,i,j;
    clrscr();
    printf("How many names?\n");
    scanf("%d",&n);
    printf("Enter %d names \n",n);
    for(i=0;i < n;i++)
    {
        list[i]=(char *)malloc(100);
        flushall();
        gets(list[i]);
    }
    for(i=0;i < n-1;i++)
    {
        for(j=i+1;j < n;j++)
        {
            strcmp(list[i],list[j]);
            {
                strcpy(temp,list[i]);
                strcpy(list[i],list[j]);
                strcpy(list[j],temp);
            }
        }
    }
    printf("The %d names in sorted order are\n",n);
    for(i=0;i < n;i++)
    {
        puts(list[i]);
    }
}//main

This entry was posted in . Bookmark the permalink.

Leave a reply