As already noted, the problem is in the format specifier you used with printf()
: %d
(which you used) is not good for double
s; you should use something like %f
or %g
instead. See this Q&A on StackOverflow for more details.
Something like:
printf("%g ", stuff[i]);
should be just fine.
(Note that you don't need to pass "%s"
and single-space string literal to printf()
either.)
Moreover, I'd like to show you how to better write your compare()
function:
You can assign the raw void*
pointers to some constant value at the beginning of function body, to avoid repeating the (ugly) casts, and making the code clearer and more readable.
You may want to simplify your if...else if...else
structure, and just use a simpler if...return
structure.
Something like this:
static int compare(const void * a, const void * b)
{
const double lhs = *(const double *)a;
const double rhs = *(const double *)b;
if (lhs > rhs)
return 1;
if (lhs < rhs)
return -1;
return 0;
}