#include #include /* Returns a pointer to the data */ /* itemsRead is set by reference to #items read */ int * getInts( int * itemsRead ) { int numRead = 0, arraySize = 5, inputVal; int *array = malloc( sizeof( int ) * arraySize ); if( array == NULL ) return NULL; printf( "Enter any number of integers: " ); while( scanf( "%d", &inputVal ) == 1 ) { if( numRead == arraySize ) { /* Array doubling code */ arraySize *= 2; array = realloc( array, sizeof( int ) * arraySize ); if( array == NULL ) return NULL; } array[ numRead++ ] = inputVal; } *itemsRead = numRead; return realloc( array, sizeof( int ) * numRead ); } void print1( int arr[], int n ) { int i; for( i = 0; i < n; i++ ) printf( "%d ", arr[ i ] ); printf( "\n" ); } void print2( int arr[], int n ) { int *endMarker = arr + n; int *p = arr; while( p != endMarker ) printf( "%d ", *p++ ); printf( "\n" ); } int main( void ) { int numItems; int *arr; arr = getInts( &numItems ); print1( arr, numItems ); print2( arr, numItems ); }