/* File: struct2.c Array of records. */ #include #include #include "genlib.h" #include "simpio.h" #include "strings.h" typedef struct dummy_tag { string name ; string major ; double gpa ; } student_record ; /* Function prototypes */ student_record read_record() ; void print_record(student_record) ; main() { student_record students[20] ; int i, size ; size = GetInteger() ; for (i = 0 ; i < size ; i++) { students[i] = read_record() ; } printf("Fourth student is: \n") ; printf("%20s, %10s, GPA: %1.4f\n\n", students[3].name, students[3].major, students[3].gpa) ; for (i = 0 ; i < size ; i++) { print_record(students[i]) ; } } /* Read in one record */ student_record read_record() { student_record rec ; rec.name = GetLine() ; rec.major = GetLine() ; rec.gpa = GetReal() ; return(rec) ; } /* Print out one record neatly */ void print_record (student_record rec) { printf("%20s, %10s, GPA: %1.4f\n", rec.name, rec.major, rec.gpa) ; }