Many of the C mini projects students find online still begin with #include <graphics.h> or #include <conio.h>. Both headers come from Borland’s Turbo C of the early 1990s. No current compiler ships graphics.h, and conio.h exists only on Windows. So the first thing a beginner learns from these projects is how to fight a compiler error that has nothing to do with C.
The 15 projects on this page use only the C standard library, so each one builds with a single command on GCC, Clang or Visual Studio. They run from a menu-driven unit converter to a working text editor, and they are grouped in three levels so you can work through them in order. Each project explains what you will build, the concepts it practices, how it works and the one or two “why” questions it answers; the complete, tested program is on GitHub. Every program compiles with zero warnings under GCC, Clang and Visual Studio in C11 and C17, and its sample sessions are re-run automatically on Linux and Windows whenever the code changes.
What Is a Mini Project in C?
A mini project in C is a small, complete program, usually a few hundred lines in a single file, that solves one real task from start to finish: it reads input, processes it and produces useful output. Mini projects turn separate topics such as loops, arrays, structs and files into working software, which is why they are the usual next step after the basics.
A good mini project is small enough to finish in an evening or a weekend, but big enough that you have to make decisions: how to store the data, how to split the work into functions, and what to do when the user types something unexpected. That last question matters more than beginners expect, and every project here answers it.
How to Build and Run These Projects
Every project is one .c file. With GCC or Clang (Linux, macOS, or Windows with MSYS2 or WSL):
gcc -std=c11 -Wall -Wextra -o unit_converter unit_converter.c
./unit_converter
With Visual Studio, open a Developer Command Prompt and run:
cl /W4 unit_converter.c
unit_converter.exe
-Wall -Wextra (or /W4) turns on the warnings that catch most beginner mistakes, so keep them on. Each project folder also contains a tests/ folder with a sample input file. Running ./unit_converter < tests/session.txt feeds the whole session to the program at once, which is how the repository checks every program automatically.
All 15 C Mini Projects at a Glance
| # | Project | Level | What you practice | Source code |
|---|---|---|---|---|
| 1 | Unit Converter | 1 | Menu loops, functions, lookup tables, safe number input | unit_converter.c |
| 2 | Profit and Loss Calculator | 1 | Arithmetic, if/else, percentages, formatted output | profit_loss_calculator.c |
| 3 | Hangman | 1 | Strings, arrays indexed by letter, argc/argv | hangman.c |
| 4 | Swat the Fly | 1 | Your own random generator, uint32_t, pointers, arrays | swat_the_fly.c |
| 5 | Grade Report | 1 | Arrays, averages, highest and lowest marks, letter grades | grade_report.c |
| 6 | Balloon Shooter | 2 | Structs, an array of structs, enum, a game loop | balloon_shooter.c |
| 7 | Sliding Number Puzzle | 2 | 2D arrays in a struct, Fisher–Yates shuffle, solvability | sliding_puzzle.c |
| 8 | Fly Away: Airport Text Adventure | 2 | Enums, designated initializers, parsing commands, a game loop | fly_away_adventure.c |
| 9 | Mini Piano | 2 | Note frequencies with pow, sine waves, binary files (WAV) | mini_piano.c |
| 10 | Personal Diary | 2 | Text files, append mode, dates with time.h, searching | personal_diary.c |
| 11 | Address Book | 3 | Arrays of structs, CSV files, search and sort | address_book.c |
| 12 | Birthday Reminder | 3 | Date arithmetic, sorting by next occurrence | birthday_reminder.c |
| 13 | To-Do Organizer | 3 | malloc and realloc, a growing array, save and load | todo_organizer.c |
| 14 | Library Management System | 3 | Related structs, issue and return, due dates, files | library_management.c |
| 15 | Text Editor | 3 | Dynamic memory, line buffers, command parsing | text_editor.c |
Level 1: Your First C Projects
These five projects need only variables, loops, if/switch, functions, arrays and strings, plus a first look at pointers in Swat the Fly. If you have finished a first C course, start here.
1. Unit Converter in C
A menu-driven converter for everyday units, and the best first project in this set.
What you’ll build: a program that converts length, mass, temperature and volume. You pick a category, a “from” unit, a “to” unit and a value, and the program prints the result and returns to the menu. For example, 26.2 miles is 42.1648 km.
What you’ll practice:
- A menu loop that runs until the user quits
- Small functions with one job each
- A lookup table (an array of structs) instead of a long
ifchain - Reading numbers safely with
fgetsandstrtod - Checking input against real-world limits
How it works: each unit is stored in a table with its size in one base unit per category, such as the metre for length. Converting is two steps: multiply into the base unit, then divide out of it. Eight units need eight numbers instead of 56 separate formulas. Temperature is the exception, because its scales start at different zeros. It goes through Celsius instead, and a value below absolute zero (−273.15 °C) is rejected. Every number is read as a whole line and checked before it is used, so typing abc, 12abc or 1e999 gets a polite “please enter a number” instead of a crash or an endless loop.
Special notes:
- The conversion factors are exact by definition, not rounded: the inch is exactly 0.0254 m and the pound exactly 0.45359237 kg. NIST lists them in its Guide to the SI, Appendix B.
- Results are printed with
%.6g, so 98.6 °F shows as37 C, not37.000000 C. - Its input functions are reused, unchanged, by most of the later projects.
Why convert through a base unit? Because the number of formulas grows with every unit you add. With a base unit, adding a new unit means adding one row to the table, and no other code changes.
Why not just use scanf? When the user types letters, scanf("%lf", ...) fails and leaves them in the input, so a loop that calls it again fails forever. Reading a line with fgets and converting it with strtod lets the program check exactly where the number ended.
Source code: unit_converter.c on GitHub
2. Profit and Loss Calculator in C
A small business calculator that gets money right to the cent.
What you’ll build: a calculator that works out the profit or loss on a sale, the selling price needed for a target profit, and the break-even quantity, which is how many units must be sold to cover the fixed costs.
What you’ll practice:
if/else if/elsewith three outcomes- Storing money as whole cents in a
long long - Turning text into a number by hand, one digit at a time
- Guarding every division against zero
- The difference between markup and margin
- Integer ceiling division
How it works: every amount is stored as a whole number of cents, so 12.50 becomes 1250, and all totals are exact integer arithmetic. A custom parser accepts exactly what a price looks like: digits, then optionally a dot and one or two more. So 12.345, -5 and 1,250 are rejected instead of being silently rounded. The profit report shows two percentages for the same profit, markup on cost and margin on selling price. Break-even divides the fixed costs by what each unit earns and rounds up, because selling 333.33 units is not possible.
Special notes:
- A profit of 250.00 on costs of 1250.00 is a 20% markup but only a 16.67% margin. Mixing the two up is one of the most common mistakes in profit and loss problems.
- With fixed costs of 5000.00 and 15.00 earned per unit, the answer is 334 units: 333 falls just short.
- The largest allowed amount times the largest quantity still fits in a
long long, so no total can overflow.
Why store money in cents? A double cannot hold most decimal fractions exactly: adding 0.10 ten times gives 0.99999999999999989, not 1. Whole cents add and multiply exactly.
Why are markup and margin different? They divide the same profit by different amounts: markup by the cost, margin by the selling price. The selling price is larger, so the margin is always the smaller percentage.
Source code: profit_loss_calculator.c on GitHub
3. Hangman Game in C
The classic word game, and a friendly introduction to strings in C.
What you’ll build: a game that picks a secret word and shows a blank for each letter. You guess one letter at a time; correct letters are filled in, and each wrong one adds a part to the hanged man. Six wrong guesses lose the game. Run it with --word and a friend can choose the word.
What you’ll practice:
- Strings as arrays of
charthat end in'\0' - An array of 26
bools indexed by letter - A table of strings for the drawing
isalpha()andtoupper()with the cast they need- Command-line arguments with
argcandargv
How it works: the secret word is a string, and the game keeps one bool per letter of the alphabet to remember which letters have been tried. letter - 'A' turns a letter into a number from 0 to 25, so checking whether R has been guessed is a single array lookup. A repeated guess costs nothing. The gallows is never drawn with if statements: only three rows of the picture change, so they are stored in a table with one entry per number of misses.
Special notes:
- The guess is read as a whole line and must be exactly one letter, so
ab,7and an empty line are rejected. letter - 'A'relies on A to Z having consecutive codes, which is true in ASCII. C itself only guarantees it for the digits'0'to'9'.
Why is there a --word option? rand() may produce a different sequence on every C library, even with the same seed. A fixed word lets a friend set the puzzle, and lets the repository’s tests replay exactly the same game on Linux and Windows.
Why cast to unsigned char before isalpha()? On many systems char is signed, so a byte from an accented letter arrives as a negative number, and passing that to isalpha() is undefined behaviour. The cast makes it safe.
Source code: hangman.c on GitHub
4. Swat the Fly Game in C
A turn-based game of memory and quick arithmetic, with a random number generator you write yourself.
What you’ll build: a fly sits on a wall of nine spots. The program lists its hops, such as “right, right, left”, and you swat the spot where it landed. A hit scores a point; a miss costs one of three lives and shows the fly’s real path. Every round the fly hops once more.
What you’ll practice:
- Writing a small random number generator
uint32_tand unsigned arithmetic that wraps around- Passing values by pointer so a function can change them
- Storing a path in an array and printing it back
- Checking a number given on the command line
How it works: the random numbers come from a linear congruential generator, the same formula the C standard prints as its example rand(). Because its state is a uint32_t, the arithmetic wraps the same way on every compiler. Each round draws a start spot and the hops, and stores every spot the fly visits. A hop that would leave the wall bounces back. The score and lives live in main(), and the round function updates them through pointers.
Special notes:
- The same seed gives the same game everywhere: games 42 and 7 produce identical fly paths with GCC, Clang and Visual Studio.
- The seed is checked carefully, because
strtoul()would happily accept-1,+5or leading spaces. - The same formula appears in the POSIX specification of rand().
Why not use rand()? The C standard does not say which sequence rand() produces, so the same seed gives a different game on Linux and on Windows. A generator you write yourself behaves the same everywhere, which makes the game testable and lets two friends race on “game number 7”.
Why write (*score)++ with parentheses? Without them, *score++ moves the pointer instead of adding to the score. GCC and Clang both warn about it, which is one more reason to keep warnings on.
Source code: swat_the_fly.c on GitHub
5. Student Grade Report in C
A report card for a whole class, built on two-dimensional arrays.
What you’ll build: you enter the subjects, the students and their marks. The program prints each student’s total, average and letter grade, and each subject’s average, highest and lowest mark. It also prints the class average, the top student and how many students got each grade.
What you’ll practice:
- Two-dimensional arrays: one row per student, one column per subject
- Several names stored in a 2D
chararray - Passing a 2D array to a function
- The integer division trap
- Running totals, highest and lowest values
- A lookup table for letter grades, and lining up columns with
printfwidths
How it works: all the marks live in one array, marks[student][subject]. The report card walks it row by row, one student at a time, and the subject statistics walk it column by column, with the same nested loop turned around. Every average goes through one small function that converts to double before dividing. The letter grade comes from a short table of cut-offs (90, 80, 70, 60) instead of a chain of if statements, and >= makes exactly 90.00 an A.
Special notes:
- When a 2D array is passed to a function, the parameter must spell out the column size,
int marks[][MAX_SUBJECTS], so the compiler knows how far apart the rows are. - Subject names are limited to 7 characters so every column keeps a space between names.
Why does 275 / 3 give 91? Dividing one int by another throws the fraction away before the result is stored. Converting one side first, (double)total / count, keeps the 91.67.
Why start the highest and lowest at the first mark? A “lowest so far” that starts at 0 never changes, because no mark is below 0. Starting both from the first student’s mark makes every comparison meaningful.
Source code: grade_report.c on GitHub
Level 2: Structured Programs
These five projects use struct and enum to describe the things a program works with: balloons, a puzzle board, the rooms of an airport, notes and diary entries. Two of them also write files. Each program is still one file, but it is organised around its data instead of around a single loop. If either keyword is new, read the guides to structures in C and enum in C first.
6. Balloon Shooter Game in C
A turn-based shooting game on a text grid, organised around structs.
What you’ll build: balloons rise through an 8 × 8 sky: slow ones (o) rise one row per turn, fast ones (O) two. Each turn you shoot one row, with 15 arrows for 12 balloons. Your arrow flies while the balloons rise, so you must aim where a balloon will be.
What you’ll practice:
- A
structfor one game object, and an array of them - A second
structthat holds the whole game, passed by pointer - An
enumfor the game status - A game loop: draw, read input, update, check
- Keeping the game’s data separate from the picture on screen
How it works: each balloon is a struct with its row, column, speed and an active flag, and the whole game lives in one Game struct. Every turn the loop draws the sky, reads a row, moves the balloons up, checks the shot and adds new balloons. The sky is never stored as characters: draw() builds a fresh grid from the balloon array each turn, so the picture can never disagree with the data.
Special notes:
- Without a rule, a fast balloon catches up with a slow one in the same column. In a simulation of 6,000 games without it, 2,126 had two balloons in one cell; with the rule, none of 9,000 did.
- Games are seeded with the generator from Swat the Fly, so game 42 is the same on every computer.
Why are popped balloons marked inactive instead of removed? Removing an element from the middle of an array means shifting everything after it. Flipping a bool is one assignment, and every loop simply skips inactive balloons.
Why only one balloon per column? Balloons only move up, so balloons in different columns can never meet. A new balloon only appears in an empty column, which makes the “two balloons in one cell” bug impossible instead of handling it in code.
Source code: balloon_shooter.c on GitHub
7. Sliding Number Puzzle (15-Puzzle) in C
The classic sliding-tile puzzle, and a lesson in why a fair shuffle needs some mathematics.
What you’ll build: a 3 × 3 (8-puzzle) or 4 × 4 (15-puzzle) board of numbered tiles with one gap. You slide tiles into the gap until they are in order, and the program counts your moves. An easy level and a hard level shuffle the board in different ways.
What you’ll practice:
- A 2D array inside a struct
- Treating a 2D board as a 1D list with
/and% - The Fisher–Yates shuffle
- Counting inversions with nested loops
- Checking that a move is legal
How it works: the board is a 2D array, but shuffling and counting are easier on a flat list. Cell number i is at row i / size and column i % size. The easy level starts from the solved board and makes 20 random legal slides, so it is always solvable. The hard level shuffles every tile with Fisher–Yates, then counts inversions (pairs of tiles in the wrong order) to decide whether the board can be solved. If it cannot, swapping two tiles fixes it.
Special notes:
- For the 8-puzzle, exactly 181,440 of the 362,880 possible arrangements can be solved. A search of every reachable position confirms it.
- On a 3 × 3 board, a board is solvable when the number of inversions is even; on a 4 × 4 board, the gap’s row also counts.
Why can half of all shuffles not be solved? On a 3 × 3 board, sliding a tile never changes whether the inversion count is even or odd, and the solved board has an even count (on a 4 × 4 board the gap’s row is part of the same rule). Swapping two tiles always flips it, which is why one swap moves a board into the solvable half.
Why Fisher–Yates? It gives every arrangement exactly the same chance. Simpler “swap random pairs” shuffles favour some arrangements over others.
Source code: sliding_puzzle.c on GitHub
8. Fly Away: A Text Adventure Game in C
A short text adventure set in an airport, where every move costs a minute.
What you’ll build: your flight leaves in 15 minutes. You type commands such as n, take passport and board to get from the taxi drop-off to the right gate, past check-in, security and a gate change. Looking around and checking your bag are free; a coffee costs three minutes.
What you’ll practice:
- An
enumfor every set of names: rooms, directions, items, commands - A struct that holds the whole game
- A map stored as data with designated initializers
- Splitting a line into a verb and a noun
- Comparing words with
strcmp - A game loop with one place where time is spent
How it works: the seven places are rows of a table, and each row says which room lies north, south, east and west. The table is filled in by name with designated initializers, such as [CHECK_IN] = {...}. Moving is then a single lookup. Each command is trimmed, lowercased and split into a verb and a noun. Every handler returns what it cost, and the main loop subtracts that in exactly one place, then checks the clock.
Special notes:
- The shortest winning route takes 8 minutes, so the best possible finish leaves 7 to spare. A search of every reachable game state confirms it.
- Boarding on your very last minute still wins, because the clock is checked after the game has been won.
Why compare words with strcmp and not ==? line == "take" compiles, but it compares the addresses of two strings, not their letters, so it is almost never true. The guide to comparing strings in C covers the alternatives.
Why store the map as a table? Adding a room means adding one row, not writing more if statements. And any exit not listed is automatically “nowhere”, because the first enum value is 0.
Source code: fly_away_adventure.c on GitHub
9. Mini Piano in C (Write a WAV File)
A program that turns typed notes into a sound file you can play, using no sound library at all.
What you’ll build: you type a tune such as C4 E4 G4 C5, choose how long each note lasts, and the program writes a WAV file that any media player opens. Type ode to load the opening of Beethoven’s Ode to Joy.
What you’ll practice:
- Turning note names into frequencies with
pow() - Making a sound wave with
sin(), sample by sample - Writing a binary file with
"wb" - Little-endian numbers and a fixed file header
- Splitting a line into words with
strtok()
How it works: each note name becomes a MIDI note number (C4 is 60, A4 is 69), and the frequency is 440 × 2 to the power (n − 69) / 12, so C4 is 261.63 Hz. Each note is a sine wave of 22,050 samples per second, scaled to 30% volume, with a 10 ms fade in and out to avoid clicks. The file starts with a 44-byte header that describes the format, written one byte at a time, lowest byte first. Then come the samples as 16-bit numbers.
Special notes:
- Six notes of 400 ms make a file of exactly 105,884 bytes: 6 × 8,820 samples × 2 bytes, plus the header.
- On Linux, add
-lmafter the source file, or the linker cannot findsinandpow. - The same
tune.wavcame out byte-identical from GCC on Linux and from Visual Studio on Windows.
Why does the file need "wb"? On Windows, text mode turns every byte with the value 10 into two bytes. Sound data contains that value by chance, so tune.wav grew by 562 bytes and every sample after the first extra byte was misaligned. On Linux the two modes are the same, so the bug hides until someone runs the program on Windows.
Why write the bytes one at a time? A WAV file is little-endian on every computer, but fwrite of a number or a struct uses the computer’s own byte order and may include padding. Writing each byte explicitly produces the same file everywhere.
Source code: mini_piano.c on GitHub
10. Personal Diary in C
A diary kept in a plain text file: the first project whose data survives after the program ends.
What you’ll build: you write an entry, and the program stamps it with today’s date and adds it to the file. You can list every entry or search them for a word, ignoring case. Close the program, run it again tomorrow, and yesterday’s entries are still there.
What you’ll practice:
- File modes:
"a"to append,"r"to read - Treating a missing file as an empty diary (
errno == ENOENT) - Reading a text file line by line with
fgets - Today’s date with
time(),localtime()andstrftime() - Checking a date by hand, including the leap-year rule
- A case-insensitive search written by hand
How it works: each entry is one line of the file, such as 2026-12-01 | Started the C mini projects.. Writing opens the file in append mode and adds one line. Reading opens it with "r". A missing file simply means an empty diary, while any other error is reported. Each line is split at the first " | " without copying anything: the separator is overwritten with '\0', so one buffer holds both the date and the text. Search results keep their numbers from the full list. The guide to file handling in C covers every file mode.
Special notes:
- The leap-year rule has three parts: 2024 and 2000 are leap years, 1900 is not.
--today 2026-12-01replaces the clock, so the tests give the same result on any day.- A line edited by hand to be longer than 319 characters would be split in two; Project 13 shows how to read lines of any length.
Why "a" and not "w"? "w" empties an existing file the moment it opens it, so every new entry would erase the whole diary. "a" always adds to the end.
Why write your own case-insensitive search? The C library has no standard one: strcasestr exists on Linux and macOS, but not in standard C or on Windows. Two nested loops with tolower() do the job anywhere.
Source code: personal_diary.c on GitHub
Level 3: Small Applications
These five projects are small applications. Each one keeps its data in a file between runs, checks what it loads, and saves through a temporary file, so a failed write never damages the file you already had. Two new ideas arrive here: dynamic memory (malloc, realloc and free) in the To-Do Organizer, and records that refer to each other by ID in the Library Management System. The Text Editor brings everything together.
The programs are longer, from about 600 to 900 lines, but 15 to 24 percent of each file is functions copied unchanged from earlier projects: the input helpers from Project 1, the date checks from the diary, the case-insensitive comparison from the address book. Reusing tested code instead of rewriting it is how real programs grow.
11. Address Book in C
An address book stored in a CSV file that Excel, LibreOffice or any text editor can open.
What you’ll build: a contact list with a name, phone number and email for each person. You can list contacts by name or by email, add, search and delete them, and save. If you quit with unsaved changes, the program asks first. Names such as Smith, John or Ana "Ani" Lopez survive the trip to the file and back.
What you’ll practice:
- An array of structs kept in sorted order
qsort()with your own comparison functions- Comparing strings while ignoring case
- Copying a whole struct with
= - Deleting from an array with
memmove() - Reading and writing CSV correctly
- A safe save and an “unsaved changes” flag
How it works: the contacts are kept sorted by name with qsort, which takes your comparison function as an argument and calls it whenever it needs to order two contacts. The email list sorts a copy, so the numbers used by Delete never change. CSV fields that contain a comma or a quote are written inside double quotes, with every quote doubled, the rule in RFC 4180. The reader understands the same rule. Saving writes a temporary file first and then replaces the old one, so a failed write never damages the existing file.
Special notes:
- Bad lines in a hand-edited file are skipped and counted, never fatal: a wrong number of fields, an unclosed quote, an invalid phone or email, or a duplicate name.
- 5,000 random contacts full of commas and quotes were written and read back unchanged, and every line matched Python’s own CSV writer.
Why does strcmp sort “Smith” before “ben”? It compares character codes, and in ASCII every uppercase letter comes before every lowercase one. Lowercasing both letters before comparing puts names in the order a reader expects.
Why memmove and not memcpy to delete? Deleting shifts the later contacts down by one place, so the source and destination overlap. memmove handles overlapping memory; with memcpy the result is undefined.
Source code: address_book.c on GitHub
12. Birthday Reminder in C
A birthday list that greets you with the birthdays coming up this week.
What you’ll build: a program that keeps names and birth dates in a text file. At start-up it shows whose birthday is today or in the next 7 days, and the full list shows everyone soonest first, with the age they are about to turn. You can add and delete people, and every change is saved straight away.
What you’ll practice:
- A
Datestruct passed and returned by value - Day-of-year and days-between arithmetic with no library date functions
- A special rule for 29 February
- Sorting by a value the program calculates
- Breaking ties with a second comparison
How it works: for each person, the program works out the next birthday: this year’s date, or next year’s if it has passed. It then counts the days until it with whole-day integer arithmetic. Because the next birthday is never more than a year away, two cases cover everything: the same year, or the rest of this year plus part of the next. The days-away value is calculated once per person, the list is sorted by it with qsort, and ties are broken by name, ignoring case.
Special notes:
- People born on 29 February celebrate on 28 February when the year is not a leap year. The rule lives in one small function, so changing it to 1 March is a one-line edit.
- The date arithmetic was checked against Python’s calendar for seven birth dates on every day from 2000 to 2400.
- The order of the stored list does not matter, so deleting a person moves the last person into the gap instead of shifting everyone down.
Why not use mktime()? It works in local time, so a daylight-saving change can make a “day” 23 or 25 hours long, and dividing seconds by 86,400 can be off by one. Counting whole days gives the same answer on every computer.
Why calculate the sort key before sorting? qsort calls the comparison function many times for each element. Working out a birthday inside it would repeat the same date arithmetic over and over.
Source code: birthday_reminder.c on GitHub
13. To-Do List Organizer in C
A to-do list with priorities and due dates, and the first project with dynamic memory.
What you’ll build: a task list saved to a text file after every change. Each task has a priority (high, medium or low), an optional due date and a done mark. The list shows unfinished tasks first, then by priority and due date, and marks anything overdue or due today. Unlike every earlier program, it has no fixed limit on the number of tasks or their length.
What you’ll practice:
malloc,reallocandfree- A growing array: a pointer, a count and a capacity
- Reading a line of any length
- Sorting an array of pointers with
qsort - Removing many elements in one pass
- Proving there are no memory leaks
How it works: the tasks live in an array that starts with room for 4 and doubles (8, 16, 32…) whenever it fills. Each task’s text is its own malloced copy, sized exactly. To list the tasks, the program sorts a separate array of pointers to them, so each task keeps its position, which is the number you type to mark or delete it. A file line of any length is read into a buffer that starts at 16 bytes and doubles as needed. Every malloc has exactly one free. See malloc vs calloc in C for the allocation functions themselves.
Special notes:
YYYY-MM-DDdates sort correctly as plain text, sostrcmpagainst today’s date decides “overdue”.- Removing one
freecall and running the tests under AddressSanitizer reports 236 bytes leaked in 4 allocations, and the test fails. Compile with-g -fsanitize=addressto check your own programs the same way. strdup()only became standard C in C23, so the program uses its own four-line copy function.
Why put the realloc result in a temporary pointer? If realloc fails it returns NULL but the old array is still there. Writing items = realloc(items, ...) would overwrite the only pointer to it: the tasks would be lost and the memory leaked.
Why sort pointers instead of the tasks? Each task’s position is the number the user types, so the tasks themselves must not move. Sorting a temporary array of pointers changes only the display order.
Source code: todo_organizer.c on GitHub
14. Library Management System in C
A library desk program with three kinds of record that refer to each other.
What you’ll build: a system of books, members and loans. You can add books and members, issue a book for 14 days, and take it back, with a fine of 0.25 for each day late. A report lists everything on loan, soonest due first. All three kinds of record live in one text file, one per line, each marked with a letter: B, M or L.
What you’ll practice:
- Structs that refer to each other by ID
- Looking records up by ID
- Values that are counted, not stored
- Rules that keep linked data consistent
- Date arithmetic across months and years
- Money in whole cents
How it works: a loan stores only a book ID and a member ID, like a row in a database table, and the program looks up the title and name when it prints. The number of copies on the shelf is never stored; it is counted from the loans every time. Issuing checks that the book and the member exist, that the member has fewer than 3 books and not this one already, and that a copy is free. After loading the file, the program drops any loan that breaks these rules, so a hand-edited file cannot corrupt the data.
Special notes:
- A due date can cross a month or year: 2026-12-20 plus 14 days is 2027-01-03. Turning each date into a day number makes the days between two dates one subtraction.
- A member with books on loan cannot be removed, or their loans would point at nobody.
- The date functions were checked against Python’s calendar for every date from 1900 to 2400.
Why link records by ID and not by name or pointer? A copy of a name goes stale when the name is corrected, and a pointer into an array points at the wrong record after an earlier one is removed. An ID stays valid and can be written to a file.
Why count available copies instead of storing them? A stored count is wrong forever if one code path forgets to update it. Counting from the loans takes microseconds and is always right.
Source code: library_management.c on GitHub
15. Text Editor in C
A working line editor in standard C, which brings every earlier idea together.
What you’ll build: an editor that opens a file, or starts a new one, and edits it with short commands:
pprints lines;aadds lines after any line;cchanges a line;ddeletes;ffinds a word;rreplaces text everywhere;wsaves, andqquits.
The prompt changes to edit*> while there are unsaved changes, and quitting asks before throwing them away. Lines can be any length, and indentation is kept exactly.
What you’ll practice:
- Text stored as an array of pointers to strings,
char ** - Inserting and deleting in the middle of a dynamic array
- Building a new string of exactly the right size
- Parsing commands with optional line numbers
- Reading lines of any length, from a file and from the keyboard
- An unsaved-changes flag and “save as”
How it works: the file is held as an array of pointers, one per line, each pointing to its own malloced string. Inserting or deleting a line moves only pointers, never the text. Replace builds each changed line in two passes: count the matches, allocate exactly the right size once, then copy the pieces. Typed lines are read with the same any-length line reader as the file, because the keyboard (stdin) is a FILE * too. Every command’s line numbers are checked against the current file before they are used.
Special notes:
- This is a line editor, like Unix
ed, the editor that came before full-screen editors such as vi. It needs no cursor keys or screen control, so it runs in any terminal. - Find (
f) ignores case; replace (r) matches exactly, and the help text says so. - 2,000 random editing sessions matched an independent model of every command, with no memory errors or leaks.
Why store the text as an array of lines? Inserting a line into a 100,000-line file moves 99,999 pointers, 8 bytes each, however long the lines are. In one big string, every character after the insertion point would have to move.
Why does replace need two passes? The new line’s size must be known before the malloc, and it depends on how many matches there are. So the first pass counts and the second copies.
Source code: text_editor.c on GitHub
Five Mistakes Beginners Make in These Projects
Every one of these mistakes appears in C projects that students hand in, and every one has a project above that shows the fix.
1. Reading input with scanf and trusting it. scanf("%d", &n) stops at the first character that is not part of a number and leaves it in the input. Type abc into a loop that calls it again, and it fails again, forever. scanf("%s", name) is worse: it stores the whole word the user types, even past the end of the array. Fix: read a whole line with fgets, then convert it with strtol or strtod and check where the number ended, as read_int() and read_double() do in the Unit Converter.
2. Comparing strings with ==. if (command == "quit") compiles, but it compares two addresses, not two words, and is almost never true. Fix: strcmp(command, "quit") == 0, as in the parser of Fly Away. To ignore case, write a small comparison loop with tolower, as the Address Book does, because strcasecmp is not standard C.
3. Dividing two integers and expecting a fraction. 275 / 3 is 91 in C, not 91.67. The fraction is thrown away before the result is ever stored in a double. Fix: convert one side first, (double)total / count, and do it in one function so it cannot be forgotten, as the Grade Report does.
4. Opening a file in the wrong mode. "w" empties an existing file the moment it opens, which would erase the Personal Diary on every entry; adding to a file needs "a". And on Windows, text mode turns every byte with the value 10 into two bytes. The Mini Piano‘s WAV file grew by 562 bytes that way, misaligning every sample after the first extra byte. Fix: "a" to add, "w" only to replace, and "rb"/"wb" for anything that is not text.
5. Losing track of memory. Writing items = realloc(items, size) loses the only pointer to the old array if realloc fails, and forgetting a single free leaks memory every time the program runs. Fix: put the realloc result in a temporary pointer first, give every malloc exactly one free, and check with AddressSanitizer (-fsanitize=address), which reports leaks on Linux. The To-Do Organizer shows all three.
Bigger C Projects to Try Next
Once these 15 feel comfortable, the next step is programs with more moving parts: real-time input, larger data structures, or a whole game loop. These guides on MYCPLUS each build one complete program in modern, standard C or C++:
- Pattern programs in C: nested loops, practised on star, number and alphabet patterns. A good warm-up if Level 1 felt hard.
- Snake game in C: a real-time game in the terminal: the program keeps moving while it waits for your keys.
- Brick breaker game in C: a 2D array of bricks, collision rules and a game loop, one step beyond the Balloon Shooter.
- Linked list in C: a list that grows one node at a time, the natural next step after the growing arrays of Projects 13 and 15.
- Car race game in C++: the same kind of game written with classes, for when you move on to C++.
- Bank management system in C: accounts, transfers and monthly interest across seven source files, with money kept in whole cents and a ledger the program checks on every start. The next step up from the record keepers in Projects 11 to 14.
Key Takeaways
- A mini project in C is a small, complete program that solves one real task. These 15 run from 231 to 869 lines, all in standard C, so each one builds with a single command on GCC, Clang or Visual Studio.
- Work through the three levels in order. Level 1 practises loops, functions, arrays and strings. Level 2 organises programs around
structandenum. Level 3 adds files that persist, dynamic memory and linked records. - Validate every input. Read whole lines with
fgets, convert them withstrtolorstrtod, and check the result. Almost every project relies on that one habit. - Prefer data to code. Lookup tables, a room map built with designated initializers, and values counted from records instead of stored all remove whole classes of bugs.
- Reuse tested functions. The later projects copy the input helpers, date checks and line reader unchanged, which is how real programs grow.
- Let tools check your work. Compile with
-Wall -Wextra(or/W4), and run AddressSanitizer to catch memory errors and leaks before your users do.
Frequently Asked Questions
Conclusion
These 15 projects take you from a menu-driven converter to a working text editor, one idea at a time. Along the way they cover the parts of C that matter in real programs: input that cannot crash the program, data organised in structs, files that keep their contents, and memory that is always freed. Each one is small enough to read in an evening, and every one is tested on Linux and Windows.
Pick the project that matches what you know today, build it, then change it: the Try this next ideas are where the real learning happens. When you are ready for more, the C programming section has guides to every topic these projects use.
Source Code and Tests
All programs on this page are in the mini-projects directory of the MYCPLUS C examples repository, one folder per project.
Build and test all of them:
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure
What the build checks. Every program is compiled with GCC and Clang under C11 and C17 with -Wall -Wextra -pedantic -Werror, and with Visual Studio (MSVC) under /W4 /WX, so a single warning fails the build. Each project’s sample sessions are fed to the program, and its output is compared character by character with the expected output (line endings aside). The same sessions also run under AddressSanitizer and UndefinedBehaviorSanitizer. There are 48 session tests in all, run in seven configurations (four on Linux, one sanitizer build, two on Windows): 336 test runs on every change, all passing.
What I Verified
Every program, output and number on this page was checked, not just written.
| Check | Ubuntu 24.04 (GCC 13.3, Clang 18.1) | Windows 11 (Visual Studio 2022) |
|---|---|---|
| Builds with zero warnings | GCC and Clang, C11 and C17, -Wall -Wextra -pedantic -Werror | MSVC /W4 /WX, C11 and C17 |
| Session tests (48 in all) | 48/48 in each of the four builds | 48/48 in both builds |
| Memory errors and leaks | AddressSanitizer, UndefinedBehaviorSanitizer and LeakSanitizer: 48/48 clean | Not available in these builds |
| Same results on both systems | Fixed-seed games, WAV files and dates give identical output | Identical expected files pass |
Beyond the tests, the trickier logic was checked against independent models written in Python:
- Games: 6,000 random games of Fly Away, 300 Balloon Shooter games and 800 sliding-puzzle boards.
- Puzzle maths: the solvability rule, checked against all 362,880 boards of the 8-puzzle.
- Mini Piano: both WAV files, rebuilt byte for byte.
- Dates: every date from 1600 to 2400 for the diary, and every day from 2000 to 2400 for the birthday reminder and from 1900 to 2400 for the library’s due dates.
- Address Book: 5,000 random CSV records with commas and quotes, read back with Python’s own CSV module.
- Text Editor: 2,000 random editing sessions, compared with a model of every command.
All of them agreed.




