#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZEOF(arr) (sizeof(arr)/sizeof(arr[0]))
int q_sort(char *a[],int low,int high)
{
int pivot,j,i;
char *temp;
if(low<high)
{
pivot=low;
i=low;
j=high;
while(i<j)
{
while(strcmp(a[i],a[pivot])!=1 && i<high)
i++;
while(strcmp(a[j],a[pivot])==1)
j--;
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[pivot];
a[pivot]=a[j];
a[j]=temp;
q_sort(a,low,j-1);
q_sort(a,j+1,high);
}
}
void main()
{
char *arr[]={"abc","def","ahcd"};
int i;
q_sort(arr,0,SIZEOF(arr)-1);
for(i=0;i<SIZEOF(arr);i++)
{
printf("%s\n",arr[i]);
}
}
Here, I have used quick sort algorithm to sort strings.