/* ECP: FILEname=fig7_27.c */ /* 1*/ /* Read An Umlimited Number Of Ints */ /* 2*/ /* With No Attempts At Error Recovery */ /* 3*/ /* Returns #Items Read */ /* 4*/ /* Will Fail Because Array Is A Copy Of NumArray And So */ /* 5*/ /* Changes In Where It Points Are Not Seen in NumArray */ /* 6*/ int /* 7*/ GetIntsWrong( int *Array ) /* 8*/ { /* 9*/ int NumRead = 0; /*10*/ int ArraySize = 5; /*11*/ int InputVal; /*12*/ /*13*/ Array = malloc( sizeof( int ) * ArraySize ); /*14*/ if( Array == NULL ) /*15*/ Error( "Out of memory" ); /*16*/ printf( "Enter any number of integers: " ); /*17*/ while( scanf( "%d", &InputVal ) == 1 ) /*18*/ { /*19*/ if( NumRead == ArraySize ) /*20*/ { /* Array Doubling Code */ /*21*/ ArraySize *= 2; /*22*/ Array = realloc( Array, sizeof( int ) * ArraySize ); /*23*/ if( Array == NULL ) /*24*/ Error( "Out of memory" ); /*25*/ } /*26*/ Array[ NumRead++ ] = InputVal; /*27*/ } /*28*/ return NumRead; /*29*/ }