#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUMELEM(a) (sizeof(a)/sizeof(a[0]))
main()
{
int cmpstra(const void *, const void *);
char *array[] ={"abc", "Xy", "1234", "Abc", "xyz"};
int i;
qsort(&array[0], NUMELEM(array), sizeof(char *), cmpstra);
printf ("ascending string order\n");
for (i = 0; i < NUMELEM(array); ++i)
printf("array[%d] = %s\n", i, array[i]);
return 0;
}
/* compare strings in ascending order */
int cmpstra(const void *pe1, const void *pe2)
{
return strcmp(*(char **)pe1, *(char **)pe2);
}
Output:
ascending string order
array[0] = 1234
array[1] = Abc
array[2] = Xy
array[3] = abc
array[4] = xyz