/* qsort with GCC nested functions */ #include #include int main(int argc, char **argv) { char *words[] = { "bespoken", "readouts", "coopering", "subtitling", "demographer", "censoring", "uttered", "flashes", }; enum { nwords = sizeof(words) / sizeof(words[0]) }; int k = atoi(argv[1]); int compare(const void *a, const void *b) { char *ac = *(char**)a; char *bc = *(char**)b; return ac[k] - bc[k]; } qsort(words, nwords, sizeof(words[0]), compare); for (size_t i = 0; i < nwords; i++) { printf("- %s\n", words[i]); } return 0; }