/* structs_3.c create a struct definition declare, initialize and print an AUTOMATIC ARRAY of struct variables use of the [] and . operators Tim Hoffman F03-15113 */ #include #include #include #define NUM_PERSONS 5 typedef struct { char *name; int year; /* 1=frosh, 2=soph etc */ } Person; /* Person is now a data type */ int years[] = { 3, 2, 4, 3, 3 }; char *names[] = { "Ian", "Ed", "Deepa", "Chris", "E(vil)J" }; int main( int argc, char *argv[]) { Person array[NUM_PERSONS]; int i; /* Populate each Person in the array from the global data above main */ for (i=0 ; i < NUM_PERSONS ; ++i) { array[i].name = malloc( strlen(names[i]) +1 ); strcpy( array[i].name, names[i] ); array[i].year = years[i]; } /* print the list */ for (i=0 ; i