#include #include #include #pragma warning (disable:4996) int * readInts( int * ptrCount ) { int x; int N = 2; int *arr = malloc( N * sizeof( int ) ); int count = 0; printf( "Enter numbers:\n" ); while( scanf( "%d", &x ) ) { if( count == N ) { /* make the array bigger! */ /* and N too */ N *= 2; arr = realloc( arr, N * sizeof( int ) ); } arr[ count++ ] = x; } *ptrCount = count; return arr; } /* * Read lots of strings from user. */ char * * readStrings( int * ptrCount ) { static char buffer[ 512 ]; int N = 2; char * *arr = malloc( N * sizeof( char * ) ); int count = 0; printf( "Enter strings, *** to terminate:\n" ); while( scanf( "%s", buffer ) ) { if( strcmp( buffer, "***" ) == 0 ) break; if( count == N ) { /* make the array bigger! */ /* and N too */ N *= 2; arr = realloc( arr, N * sizeof( char * ) ); } arr[ count++ ] = strdup( buffer ); } *ptrCount = count; return arr; } int main( ) { int count; char * * arr; int i; char * str1; char * str2; arr = readStrings( &count ); printf( "Read %d items\n", count ); for( i = 0; i < count; i++ ) printf( "arr[%d]=%s\n", i, arr[ i ] ); return 0; }