C Program to perform String Sorting...

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

  //String Sorting..

void main()
{
    char a[100][50],t[50];
    int n,i,j;
    printf("\nEnter the no of strings to be sorted..");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s",a[i]);
    }
    printf("\nThe sorted strings are as follows..\n");
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(strcmp(a[j],a[j+1])>0)
            {
              strcpy(t,a[j]);
              strcpy(a[j],a[j+1]);
              strcpy(a[j+1],t);
            }
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%s\n",a[i]);
    }
}

No comments:

Post a comment