#include
static char *ch[20],temp[20];
static int i,j,k,n;
char Display(char *ch[]);//Function Prototype
char SortWords(char *ch[])//Function Definitio
{
printf("\n\n------------------------------------\n\tBefore Sort\n------------------------------------\n\n");
Display(ch);
for(i = 0; i < n;i++)//Loop to compare each with word with
{
for(j = i + 1; j < n;j++)//Loop to compare each ith index word with jth index word
{
if ( strcmp(ch[i],ch[j]) > 0)// if ith index string > jth index
{
strcpy(temp,ch[j]); //swapping
strcpy(ch[j],ch[i]);
strcpy(ch[i],temp);
}
}
}
printf("\n\n------------------------------------\n\tAfter Sort\n------------------------------------\n\n");
Display(ch);
}
char Display(char *ch[])//Display the strings
{
for(i = 0; i < n;i++)
printf("%s ",ch[i]); //printin after sorting
}
//////////////////////////////////////////
main()
{
printf("Enter No of Strings\n");
scanf("%d",&n);//no of string that we enter
for(i=0;i
{
ch[i] = ((char *) malloc( 50 * sizeof(char)));
scanf("%s",ch[i]);
}
SortWords(ch);//Function Calling
}//End of Main