Skip to content
C project #09Intermediate

Student Record Management System

Add, search, update, delete and sort student records stored in a growable array and saved to a binary file.

Estimated time
~6 hours to build
Files
7 files · 547 lines
Technologies
C11, <stdlib.h>, <string.h>, Binary file I/O

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

Maintain student records (roll number, name, branch, year, CGPA). Support adding with duplicate detection, listing with a class average, searching by roll number, name fragment or branch, updating, deleting, and sorting by roll, name or CGPA. Records must persist between runs.

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.

TextArchitecture diagram
main.c (menu, input) ──calls──> student.c (StudentTable API) ──reads/writes──> students.dat
│
Student[] on the heap (realloc doubling)

Folder structure

TextProject tree
student-record-management/
├── README.md
├── Makefile
├── src/main.c
├── src/student.c
├── src/student.h
├── tests/expected-output.txt
└── tests/sample-input.txt

Complete source code

Makefile

20 lines
MakefileMakefile
# Generated for KENHOLT Skills. Usage: make | make test | make clean
CC = gcc
CFLAGS = -std=c11 -Wall -Wextra -O2
SRC := $(wildcard src/*.c)
HDR := $(wildcard src/*.h)
ARGS := $(shell cat tests/args.txt 2>/dev/null)
INPUT := $(wildcard tests/sample-input.txt)
app: $(SRC) $(HDR)
$(CC) $(CFLAGS) -Isrc $(SRC) -o app -lm
test: app
./app $(ARGS) $(if $(INPUT),< $(INPUT),) > actual.txt
diff actual.txt tests/expected-output.txt && echo "Test passed: output matches tests/expected-output.txt"
clean:
rm -f app app.exe actual.txt
.PHONY: test clean

What each file does

src/student.h
The Student and StudentTable types 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: make builds ./app, make test runs the sample session and compares it with the expected output, make clean removes build files.

How to run it

Build

Terminal
gcc -std=c11 -Wall -Wextra -Isrc src/*.c -o app -lm
# or simply: make

Run

Terminal
./app # Linux / macOS
.\app.exe # Windows

Test against the expected output

Terminal
./app < tests/sample-input.txt > actual.txt
diff actual.txt tests/expected-output.txt # no output means they match
# Windows PowerShell:
# Get-Content tests\sample-input.txt | .\app.exe > actual.txt
# Compare-Object (Get-Content actual.txt) (Get-Content tests\expected-output.txt)

Expected output

Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.

Texttests/expected-output.txt
No saved data found; starting a new register.
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number:
Name:
Branch (e.g. CSE):
Year (1-4):
CGPA (0-10):
Student 101 added.
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number:
Name:
Branch (e.g. CSE):
Year (1-4):
CGPA (0-10):
Student 102 added.
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number:
Name:
Branch (e.g. CSE):
Year (1-4):
CGPA (0-10):
Student 103 added.
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number:
Roll 101 already exists.
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll Name Branch Year CGPA
------ -------------------- ------ ---- -----
101 Asha Rao CSE 3 8.92
102 Vikram Shah ECE 2 7.45
103 Lakshmi Nair CSE 3 9.31
3 student(s), average CGPA 8.56
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number, part of a name, or branch:
Roll Name Branch Year CGPA
------ -------------------- ------ ---- -----
101 Asha Rao CSE 3 8.92
103 Lakshmi Nair CSE 3 9.31
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number, part of a name, or branch:
Roll Name Branch Year CGPA
------ -------------------- ------ ---- -----
102 Vikram Shah ECE 2 7.45
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number to update:
Name:
Branch (e.g. CSE):
Year (1-4):
CGPA (0-10):
Student 102 updated.
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Sort by 1.Roll 2.Name 3.CGPA (high first):
Roll Name Branch Year CGPA
------ -------------------- ------ ---- -----
103 Lakshmi Nair CSE 3 9.31
101 Asha Rao CSE 3 8.92
102 Vikram Shah ECE 3 7.80
3 student(s), average CGPA 8.68
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll number to delete:
Student 101 deleted.
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Roll Name Branch Year CGPA
------ -------------------- ------ ---- -----
103 Lakshmi Nair CSE 3 9.31
102 Vikram Shah ECE 3 7.80
2 student(s), average CGPA 8.55
1.Add 2.List 3.Search 4.Update 5.Delete 6.Sort 7.Save 0.Save & exit
Choice:
Saved 2 record(s) to students.dat. Goodbye.
Input
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

  1. 1Add undo for the last delete.
  2. 2Replace the binary file with a versioned format (magic number + version field).
  3. 3Support 10,000 records and measure how long sorting takes.

Built and tested it yourself? Mark it to update your dashboard.