I saw this example on a website:
I understand all of it but the compare function. Could someone explain to me in simple terms what the compare function is doing?Code:/* qsort example */ #include <stdio.h> #include <stdlib.h> int values[] = { 40, 10, 100, 90, 20, 25 }; int compare (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main () { int * pItem; int n; qsort (values, 6, sizeof(int), compare); for (n=0; n<6; n++) { printf ("%d ",values[n]); } return 0; }
Thanks,
Shane



LinkBack URL
About LinkBacks


