/*-------------------------------------------------------------------*/ /* revfn1.c */ /* Array and functions. */ /*-------------------------------------------------------------------*/ #include enum {ARRAYSIZE = 5}; /*-------------------------------------------------------------------*/ static void getNumbers(int *piNums) /* piNums is a pointer to the first element of an array. Read integers from stdin into that array. */ { int *piAfterLast; printf("Enter %d integers:\n", ARRAYSIZE); piAfterLast = piNums + ARRAYSIZE; while (piNums != piAfterLast) { scanf("%d", piNums); piNums++; } } /*-------------------------------------------------------------------*/ static void putNumbers(int *piNums) /* piNums is a pointer to the first element of an array. Print the elements of that array to stdout in reverse order. */ { int *piAfterLast; printf("The integers in reverse order are:\n"); piAfterLast = piNums + ARRAYSIZE; while (piAfterLast != piNums) { piAfterLast--; printf("%d\n", *piAfterLast); } } /*-------------------------------------------------------------------*/ int main(void) /* Read ARRAYSIZE integers from stdin, and write them in reverse order to stdout. Return 0. */ { int aiNumbers[ARRAYSIZE]; getNumbers(aiNumbers); printf("\n"); putNumbers(aiNumbers); return 0; }