// Illustrates pass by address with structures #include struct student { char fName[20]; // first name char lName[20]; // last name int socSecNumber; // social security number double gpa; // grade point average }; // some functions void LoadStudentData(struct student* sp); void PrintStudent(const struct student* sp); int main() { struct student sList[5]; // array of 5 students int i; for(i = 0; i < 5; i++) { printf("Entering data for student %d...\n", i+1); LoadStudentData(&sList[i]); } printf("\n\nPrinting student records\n\n"); for (i = 0; i < 5; i++) PrintStudent(&sList[i]); return 0; } void LoadStudentData(struct student* sp) { printf("Enter first name: "); gets(sp->fName); printf("Enter last name: "); gets(sp->lName); printf("Enter SSN: "); scanf(" %d", &(sp->socSecNumber) ); printf("Enter GPA: "); scanf(" %lf", &(sp->gpa) ); // consume remaining characters up through newline. while (getchar() != '\n') ; } void PrintStudent(const struct student* sp) // prints the internal data of any student structure passed in { printf("%-20s %-20s %10d GPA: %4.2f\n", sp->fName, sp->lName, sp->socSecNumber, sp->gpa); }