A student records system
The problem
Build a program that adds, lists, searches and sorts student records, and saves them in a file so that they are still there next time.
Requirements
- Each student is a struct with an ID, a name and a CGPA
- A menu offers add, list, search by ID, sort by CGPA, save and quit
- The records are held in an array that grows with realloc
- Saving and loading use a text file, and a missing file is handled calmly
- Bad input does not crash the program
- All memory is freed before the program ends
Technologies
- C
- Structs
- malloc and realloc
- File input and output
Step by step
- Define the struct, and write one function that prints a student.
- Write an add function that grows the array when it is full.
- Write the list and search functions, and test them.
- Write the sort, comparing by CGPA and then by name.
- Write the save function, then the load function, and check for NULL.
- Write the menu loop in main, calling one function for each choice.
- Run the program, restart it and confirm that the records came back.
- Compile with -Wall -Wextra, and fix every warning.
Expected result
A complete console program whose data survives between runs, and which handles bad input and missing files.
How it is evaluated
- Records survive a restart
- The program runs without memory errors under a sanitizer
- Every fopen and malloc is checked
- The code compiles with no warnings
- main contains only the menu and calls to functions
Ways to improve it
- Add editing and deleting of records
- Store records in a binary file with fwrite
- Add a report of the class average and the grade counts