/* isort Programm, welches ein Array von Zufallszahlen sortiert */ #include #include #define LENGTH(arr) ((sizeof(arr))/(sizeof(arr[0]))) int einfach_compare(const void *i1, const void *i2) { return *((const int*) i1) - *((const int*) i2); } int main(int argc, char *argv[]) { int rands[20]; for (int i = 0; i < LENGTH(rands); i++) { rands[i] = rand() % 50; } qsort(rands, LENGTH(rands), sizeof rands[0], &einfach_compare); for (int i = 0; i < LENGTH(rands); i++) { if (printf("%d\n", rands[i]) < 0) { perror("printf"); exit(EXIT_FAILURE); } } if (EOF == fflush(stdout)) { perror("fflush"); exit(EXIT_FAILURE); } return 0; }