#include #include #include /* * shows old style, fixed width 2D array for strings * problems: string space is too short or wasted * fixed number of rows. */ int main() { char pets[4][5]; int i; int num_pets; char str[BUFSIZ]; i = 0 ; while (1) { printf("next pet name? "); fgets(str, BUFSIZ, stdin); if ( str[0] == '\n' ) break; str[strlen(str)-1] = '\0'; // remove \n strcpy(pets[i], str); // copy into 2D array i++; } num_pets = i; for ( i = 0 ; i < num_pets ; i++ ) printf("pet[%d] is %s\n", i, pets[i]); return 0; }