You comparison function is for int
not for double
:
int cmpfunc (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
Note that comparing floating point is different than comparing integer values. Because of floating point precision, it's not enough to change int *
to double *
above, you should use an epsilon constant for comparison.
http://c-faq.com/fp/fpequal.html
EDIT: I striked the above paragraph as it is not relevant for sorting, see the comments section. I don't delete my answer to keep the comments visible.