I don't know what I'm doing wrong but the following code does not sort the array properly.
#include <stdio.h> #include <stdlib.h> int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int main() { int x[] = { -919238029, -889150029, -826670576, -579609061, -569653113, -305140505, -216823425, -193439331, -167683147, -49487019, -45223520, 271789961, 275570429, 444855014, 559132135, 612312607, 664554739, 677860351, 1005278191, 1031629361, 1089012280, 1115952521, 1521112993, 1530518916, 1907515865, 1931470931, -1631034645, -1593702794, -1465300620, -1263094822 }; int i; qsort(x, 30, sizeof(int), compare); for(i = 0; i < 30; i ++) printf("%d\n", x[i]); return 0; } produces the following output:
1521112993 1530518916 1907515865 1931470931 -1631034645 -1593702794 -1465300620 -1263094822 -919238029 -889150029 -826670576 -579609061 -569653113 -305140505 -216823425 -193439331 -167683147 -49487019 -45223520 271789961 275570429 444855014 559132135 612312607 664554739 677860351 1005278191 1031629361 1089012280 1115952521 I mean, the problem /must/ be in my compare function. Anybody notice anything strange?