Project · C Programming (from zero to systems)
Project: a clinic token queue
The brief
Dr Mehta's clinic in Nagpur gives every patient a token, and calls patients aged 60 and over first. You build the queue in C as a multi-file program with a Makefile: a struct for each patient, a heap array that grows with realloc, seniors-first calling with memmove, a text save file so the queue survives a restart, and a clean valgrind run.
Why it matters
Clinics, bank branches, passport offices and service centres all run token queues, and the C underneath is what this project practises: structs passed by pointer, memory that grows on the heap and is always freed, data saved to a file, and a build split into files with make. Interviewers for systems and embedded roles ask about exactly these: realloc, memmove, leaks and Makefiles.
Skills you practise
- structs and pointers to structs
- malloc, realloc and free
- memmove
- fprintf and fscanf
- header files and include guards
- make
- valgrind
You need
- gcc and make (Linux, WSL, or macOS with Xcode command line tools)
- valgrind for step 6: Linux or WSL (it does not run on macOS or native Windows)
What you will have at the end
A multi-file C program (queue.h, main.c, queue.c and a Makefile) that runs a seniors-first token queue, grows its array on the heap, saves and reloads the queue from queue.txt, and passes valgrind with no leaks; plus next.js with a tested nextIndex().
How it is marked (rubric, 100 points)
| Correct behaviourEvery check passes: tokens, growth to 4 and 8, seniors first, the save file and the reload carrying on at token 3. | 40 |
|---|---|
| Memory handled safelyrealloc checked through a temporary pointer, memmove for the gap, bounded name copies, and a clean valgrind run. | 25 |
| Multi-file buildA Makefile with a link rule, a pattern rule, clean and .PHONY; the header has an include guard; no warnings. | 20 |
| ExplainedYou can draw the Queue struct and its heap array before and after a realloc and a memmove. | 15 |
0/6 steps done
Step 1 of 6
Build the project with make
make clean && make compiles main.c and queue.c separately and links them into clinic, with no warnings.
Save the five files from the tabs into one folder. The program is split into files: queue.h declares the Patient and Queue structs and the functions, main.c (given) reads the commands, and queue.c, which you write, does the work. The include guard (#ifndef QUEUE_H) stops the header being pasted in twice.
make builds the first target in the Makefile. Add the link rule above the pattern rule: clinic: main.o queue.o (TAB)$(CC) $(CFLAGS) $^ -o $@ and a clean rule that runs rm -f *.o clinic, marked .PHONY. The starter queue.c already compiles (each function is a stub), so the build should finish with no warnings.
$ make clean && makeAlso check yourself
Your notes: Makefile, queue.c, next.js
Write down each command you ran. It goes into your project summary.