As you know, the qsort has the signature:
void qsort ( void * base, size_t num, size_t size, int ( * comparator ) ( const void *, const void * ) );
The following code is from http://www.cplusplus.com/reference/c...lib/qsort.html
Is it wrong? Seems
Code:
qsort (values, 6, sizeof(int), compare);
should be
Code:
qsort (values, 6, sizeof(int), &compare);
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 n;
qsort (values, 6, sizeof(int), compare);
for (n=0; n<6; n++)
printf ("%d ",values[n]);
return 0;
}