hier mal ne kaum dokumentierte lösung. die hilft nicht wirklich, aber gibt dir vielleicht eine idee...
Code:
# include <stdio.h>
# include <stdlib.h>
# define MAX_INPUT_SIZE 100
void array_ausgabe (int* a, int size) {
int i;
for (i = 0; i < size; i++) {
printf ("array[%d] == %d\n", i, a[i]);
}
} // array_ausgabe()
// oh scheisse _const void *_ was mag das wohl sein ;)
// aber du sollst ja wahrscheinlich eh deine eigene sortierfunktion schreiben...
int mycomp (const void *a, const void *b) {
return (*(int*) a) - (*(int*) b);
} // comp
int main(int ac, char **av)
{
int array[MAX_INPUT_SIZE];
int array_index = 0;
printf ("gib zahlen ein, ende bei -1\n");
int input = 0;
while (array_index < MAX_INPUT_SIZE && input != -1) {
printf ("> ");
scanf ("%d", &input);
if (input != -1) {
array[array_index++] = input;
}
}
if (array_index == MAX_INPUT_SIZE) {
printf ("mehr als %d zahlen darfst du nicht eingeben!\n", MAX_INPUT_SIZE);
}
printf ("array unsortiert:\n");
array_ausgabe(array, array_index);
printf ("array sortiert:\n");
// hier statt qsort _deine_ sortierfunktion.
// google mal nach bubblesort ...
qsort (array, array_index, sizeof (int), mycomp);
array_ausgabe(array, array_index);
return 0;
}