#include #include /* shows how a dynami array is flexible*/ #define LEN 5 int main() { int capacity; // int temps[LEN]; int *temps; // point to a dyn allocated array int i; int num_in_array; char str[BUFSIZ]; printf("How many temps do you want to store? " ); fgets(str, BUFSIZ, stdin); capacity = atoi( str ); temps = malloc( capacity * sizeof(int) ); if ( temps == NULL ) { printf("no memory available"); exit(1); } i = 0; while ( 1 ){ printf("Next temp (or Enter when done)? "); fgets( str, BUFSIZ, stdin); if ( str[0] == '\n' ) break; temps[i] = atoi( str ); i++; } num_in_array = i; // now print the list for ( i = 0; i < num_in_array; i++ ) printf(" %d", temps[i]); putchar('\n'); return 0; }