Introduction
Every college office keeps student records. This project builds a small but properly engineered record system: the data structure and file format live in their own module, the menu is separate, and every input is validated.
Problem statement
Objectives
- Design a reusable dynamic-array module with an ownership model
- Persist structs to a binary file and load them back
- Sort records with qsort and multiple comparators
- Read whole lines safely with fgets + sscanf
Features
- Duplicate roll numbers rejected
- Search by roll, name fragment or branch
- Update and delete with array compaction (memmove)
- Sort by roll, name (case-insensitive) or CGPA
- Automatic save on exit and load on start-up
Concepts demonstrated
- Dynamic arrays
- realloc growth
- qsort comparators
- Binary persistence
- Modular design
System architecture
Each module pairs a header (.h, the interface) with a source file (.c, the implementation); main.c contains only the user interface. StudentTable owns a heap array of Student structs that doubles its capacity when full. table_remove closes the gap with memmove. table_save writes a count followed by the raw structs; table_load reads them back through table_add, which also re-checks for duplicates.
Folder structure
Complete source code
Makefile
What each file does
- src/student.h
- The
StudentandStudentTabletypes and the table API. - src/student.c
- Dynamic array operations, the three qsort comparators, binary save/load and printing helpers.
- src/main.c
- Line-based input helpers (
read_line,read_int,read_double) and the menu. - Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
1 101 Asha Rao CSE 3 8.92 1 102 Vikram Shah ECE 2 7.45 1 103 Lakshmi Nair CSE 3 9.31 1 101 2 3 CSE 3 Vik 4 102 Vikram Shah ECE 3 7.80 6 3 5 101 2 0
Testing
- Run the sample session and diff with
tests/expected-output.txt. - Run the program twice: the second run must load the records saved by the first.
- Try adding roll 101 twice, a year of 5, and a CGPA of 11 — all must be rejected.
Common errors
Garbage names after loading
students.dat was written by a different version of the struct. Delete it and re-enter the data; binary formats depend on the exact struct layout.
Menu repeats or skips prompts
Don't mix scanf("%d") with fgets; this project reads every line with fgets and parses it with sscanf to avoid leftover newlines.
Possible improvements
- Export and import CSV
- Store marks per subject and compute CGPA automatically
- Add an index (sorted array + binary search) for fast lookup by roll number
Additional challenges
- 1Add undo for the last delete.
- 2Replace the binary file with a versioned format (magic number + version field).
- 3Support 10,000 records and measure how long sorting takes.
Built and tested it yourself? Mark it to update your dashboard.