/* * Functions to fill a table and print it in reverse order. * tableFill - read values into a table * tablePrintRev - print a table in reverse order */ #include int tableFill(int a[], int max) { int next; /* next input value */ int r; /* return from trying to read values */ int cnt; /* count of values read */ for (cnt = 0; (r = scanf("%i", &next)) != EOF; cnt++) { if (r != 1) /* bad return from scanf */ { printf("Error in the input after reading %i values.\n", cnt); break; } if (cnt == max) /* no room to store this value */ { printf("No more room in array after reading %i values.\n", cnt); break; } a[cnt] = next; /* save element in array */ } return cnt; } void tablePrintRev(int a[], int n) { int i; /* index used in writing values */ for (i = n - 1; i >= 0; i--) printf("%i\n", a[i]); }