Coding:
#include<stdio.h>
#include<string.h>
#include<conio.h>
int comparison(char *s,char *t);
#define MAX 20
int n;
void read();
void sort();
void display();
struct list
{
char name[20];
}names[MAX];
void main()
{
clrscr();
printf("\nSorting a Strings in Case Sensitive Order\n");
read();
sort();
display();
getch();
}
void read()
{
int i;
printf("Enter the no of names you want to enter(less than %d): ",MAX);
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter name %d: ",i+1);
scanf("%s",names[i].name);
}
}
void sort()
{
int i,j;
struct list temp;
for(i=1;i<n;i++)
{
for(j=1;j<=n-i;j++)
{
if(comparison(names[j-1].name,names[j].name)>0)
{
temp=names[j];
names[j]=names[j-1];
names[j-1]=temp;
}
}
}
}
void display()
{
int i;
for(i=0;i<n;i++)
{
printf("Name %d: %s\n",i+1,names[i].name);
}
}
int comparison(char *s,char *t)
{
while((*s)==(*t))
{
s++;
t++;
}
if((*s)>(*t))
return 1;
else
return -1;
}
Output: