/* link this with main.c in this same directory (or 2.c or 3.c) */ #include void sortfile(FILE *in, FILE *out) { int n, a[100], i; extern void sort(int *a, int size); for (n = 0; n < 100 && fscanf(in, "%d", &a[n]) == 1; n++) ; sort(a, n); for (i = 0; i < n; i++) fprintf(out, "%d\n", a[i]); } void sort(int *a, int size) { int i, j, t; for (i = 0; i < size; i++) { for (j = 0; j < size - 1; j++) { if (a[j] > a[j+1]) { /* swap */ t = a[j]; a[j] = a[j+1]; a[j+1] = t; } } } }