/* * An initial program to read values and print them in reverse order. */ #include #include #define MAXVALS 100 /* max number of values we can reverse */ int main() { int table[MAXVALS]; /* array to hold input values */ int n; /* number of values in "table" */ int i; /* index used in writing values */ int next; /* next input value */ int r; /* return code from trying to read values */ for (n = 0; (r = scanf("%i", &next)) != EOF ; n++) { if (r != 1) { printf("Input error after reading %i values.\n", n); break; } if (n >= MAXVALS) /* Make sure there's room */ { printf("No more room after reading %i values.\n", n); break; } table[n] = next; } for (i = n - 1; i >= 0; i--) printf("%i\n", table[i]); return EXIT_SUCCESS; }