Code:
char AddStudent()
{
FILE *fptr;
struct Students
{
char FirstName[SIZE];
char LastName[SIZE];
char StudentNumber[8];
char Assignments[5][4];
char Labs[5][4];
char Midterm[4];
char Final[4];
};
struct Students GNG1106[200];
fptr=fopen("E://StudentFile.txt", "a+");
if (fptr == NULL)
printf("Unable to open file");
else
{
printf("File was opened\n");
printf("Please enter the first name of the student: ");
fgets(GNG1106[0].FirstName, SIZE, fptr);
printf("\nPlease enter the last name of the student: ");
fgets(GNG1106[0].LastName, SIZE, fptr);
printf("\nPlease the student's student number: ");
fgets(GNG1106[0].StudentNumber, 8, stdin);
printf("\nPlease enter the grade out of 100 for the first assignment: ");
fgets(GNG1106[0].Assignments[0], 4, stdin);
printf("\nPlease enter the grade out of 100 for the second assignment: ");
fgets(GNG1106[0].Assignments[1], 4, stdin);
printf("\nPlease enter the grade out of 100 for the third assignment: ");
fgets(GNG1106[0].Assignments[2], 4, stdin);
printf("\nPlease enter the grade out of 100 for the fourth assignment: ");
fgets(GNG1106[0].Assignments[3], 4, stdin);
printf("\nPlease enter the grade out of 100 for the fifth assignment: ");
fgets(GNG1106[0].Assignments[4], 4, stdin);
printf("\nPlease enter the grade out of 100 for the first lab: ");
fgets(GNG1106[0].Labs[0], 4, stdin);
printf("\nPlease enter the grade out of 100 for the second lab: ");
fgets(GNG1106[0].Labs[1], 4, stdin);
printf("\nPlease enter the grade out of 100 for the the third lab: ");
fgets(GNG1106[0].Labs[2], 4, stdin);
printf("\nPlease enter the grade out of 100 for the fourth lab: ");
fgets(GNG1106[0].Labs[3], 4, stdin);
printf("\nPlease enter the grade out of 100 for the fifth lab: ");
fgets(GNG1106[0].Labs[4], 4, stdin);
printf("\nPlease enter the grade out of 100 for the midterm exam: ");
fgets(GNG1106[0].Midterm, 4, stdin);
printf("\nPlease enter the grade out of 100 for the final exam: ");
fgets(GNG1106[0].Final, 4, stdin);
fprintf(fptr, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", GNG1106[0].FirstName, GNG1106[0].LastName, GNG1106[0].StudentNumber, GNG1106[0].Assignments[0], GNG1106[0].Assignments[1], GNG1106[0].Assignments[2], GNG1106[0].Assignments[3], GNG1106[0].Assignments[4],
GNG1106[0].Labs[0], GNG1106[0].Labs[1], GNG1106[0].Labs[2], GNG1106[0].Labs[3], GNG1106[0].Labs[4], GNG1106[0].Midterm, GNG1106[0].Final);
}
fclose(fptr);
}