#include #include #include "qsort.h" const char * array[] = { "eggs", "bacon", "cheese", "mushrooms", "spinach", "potatoes", "spaghetti", "fruit", "lemons", }; static inline int compare (const void * a, const void * b) { /* The pointers point to offsets into "array", so we need to dereference them to get at the strings. */ return (strcmp (*(const char **) a, *(const char **) b) < 0); } #define n_array (sizeof(array)/sizeof(const char *)) int main () { int i; QSORT (const char *, array, n_array, compare); for (i = 0; i < n_array; i++) { printf ("%d: %s.\n", i, array[i]); } return 0; }