This is the capstone challenge — you'll combine structs, dynamic memory, and file I/O into a fully functional student records system. Everything you've learned in this course comes together here.
YOUR TASK
Write a C program that:
Defines a struct Student with: name (char[50]), id (int), grade (float)
Reads n students from stdin
Writes all records to students.txt
Re-reads the file and prints each student as: ID: X | Name: Y | Grade: Z.XX
Prints the class average grade at the end
Need a hint?
Step-by-step:
1. Define: typedef struct { int id; char name[50]; float grade; } Student;
2. Read n, then use malloc(n * sizeof(Student))
3. For each student: scanf("%d %s %f", &s[i].id, s[i].name, &s[i].grade);
4. Write to file: fprintf(f, "%d %s %.2f\n", s[i].id, s[i].name, s[i].grade);
5. Re-read and print: printf("ID: %d | Name: %s | Grade: %.2f\n", ...);
6. Compute average and print: printf("Average: %.2f\n", avg);
7. Always free(students); and fclose(f);
Example (input: 2, then "1 Alice 92.5", "2 Bob 78.0"):
ID: 1 | Name: Alice | Grade: 92.50
ID: 2 | Name: Bob | Grade: 78.00
Average: 85.25
Code Editor
Ready
Output
Console
Console initialized...
Ready for the Final Project: Student Records System
> This is your capstone — use everything you've learned!
> Hit "Check My Code" when you're ready to submit.