/** * student.c * A simple representation of students. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include // For malloc #include // For FILE, fprintf, and such #include "student.h" // Useful definitions. // +------------------------------------------------------------------ // | Exported Functions | // +--------------------+ /** * student_new (fname, lname, sid, gpa, debt) * Create a new student. Returns NULL upon failure. */ struct student * student_new (char *fname, char *lname, char *sid, double gpa, int debt) { // Allocate memory struct student *result = (struct student *) malloc (sizeof (struct student)); // Check for errors if (result == NULL) return NULL; // Fill in the fields result->fname = fname; result->lname = lname; result->sid = sid; result->gpa = gpa; result->debt = debt; // And we're done return result; } // student_new /** * student_print (student, fp) * Print information on a student to the given destination. */ void student_print (struct student *student, FILE *fp) { fprintf (fp, "%s %s\t(%s)\t[GPA: %lf, Debt: $%d.%02d]", student->fname, student->lname, student->sid, student->gpa, student->debt / 100, student->debt % 100); } // student_print