#include<stdio.h>//header file
#include<conio.h>//header file
#include<string.h>//header file
void sortstring(char *,int n);
void main() //starting of the main() function
{
int n,i,j;
char a[10][10]; //declaration of the variables
clrscr();
printf("program that sorts a list of names");
printf("\n\n\n\t\t------------INPUT-------------");
printf("\n\nenter the no. of names to be entered in the list");//taking input
from the user
scanf("%d",&n);
printf("\nenter the names in the list");
for(i=0;i<n;i++)
scanf("%s",&a[i]);
sortstring(a,n);
printf("\nthe sorted strings are=");
for(i=0;i<n;i++)
printf("\t%s",a[i]);
getch();
}
void sortstring(char *p,int n)
{
char *p1,*p2,d[10],h[10];
int i,j,s,c;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
c=0;
p1=p+(i*10);
p2=p+(j*10);
while(*p1!='\0')
{
d[c]=*p1;
c++;
p1++;
}
d[c]='\0';
c=0;
while(*p2!='\0')
{
h[c]=*p2;
p2++;
c++;
}
h[c]='\0';
s=strcmp(d,h);
if(s>0)
{
c=0;
p1=p+(i*10);
p2=p+(j*10);
while(d[c]!='\0')
{
*p2=d[c];
p2++;
c++;
}
*p2='\0';
c=0;
while(h[c]!='\0')
{
*p1=h[c];
p1++;
c++;
}
*p1='\0';
}
}
}
}