Code:
#include <stdio.h>
#include <stdlib.h>
typedef double T;
int compare(const void *a, const void *b)
{
const T *x = a, *y = b;
if ( *x > *y )
{
return 1;
}
if ( *x < *y )
{
return -1;
}
return 0;
}
int main(void)
{
T t[] = {3,2,7,4,6,9,1,3,6,0};
size_t i;
for ( i = 0; i < sizeof t / sizeof *t; ++i )
{
printf("%g,", t[i]);
}
putchar('\n');
qsort(t, i, sizeof *t, compare);
for ( i = 0; i < sizeof t / sizeof *t; ++i )
{
printf("%g,", t[i]);
}
putchar('\n');
return 0;
}
/* my output
3,2,7,4,6,9,1,3,6,0,
0,1,2,3,3,4,6,6,7,9,
*/
This to me is just easier to read. Watch what you are feeding to qsort.