/* File: struct1.c simple use 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 student1, student2, temp ; student1 = read_record() ; student2 = read_record() ; print_record (student1) ; print_record (student2) ; printf("\n") ; /* Swap records: ANSI C only */ temp = student1 ; student1 = student2 ; student2 = temp ; print_record (student1) ; print_record (student2) ; } /* 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) ; }