๐ง C Mini Projects for Practice โ Dynamic Memory, Structs, Enums & File I/O #
These projects are designed to test and reinforce your understanding of:
- Dynamic Memory Allocation (
malloc,calloc,realloc,free) - Structs and Enums
- Pointers and Arrays
- File I/O (
fopen,fprintf,fscanf, etc.) - Modular Design and Debugging
Each project can typically be completed in 1โ2 weeks with good testing and documentation.
More projects available here:
https://github.com/cpro-iiit/snake-project-starter.
https://cs50.harvard.edu/x/2023/labs/4/smiley/.
https://cs50.harvard.edu/x/2023/labs/4/volume/.
https://cs50.harvard.edu/x/2023/labs/5/.
https://cs50.harvard.edu/x/2023/labs/2/.
Reading/understanding these code and adding to it, will give you the confidence for large scale coding.
๐ Project 1: Student Record Management System #
Description #
Build a program to manage student records (name, roll number, marks, grade, etc.). Support dynamic addition/deletion of students, sorting by marks, and saving/loading from file.
Key Concepts #
- Dynamic arrays of structs
- File I/O (save/load)
- Struct assignment and deep copies
Example Features #
- Add/Delete/Update students
- Calculate class average
- Write to
records.txt
๐งพ Project 2: Inventory Tracker for a Store #
Description #
Implement a simple inventory system that tracks items, quantities, and prices.
Key Concepts #
- Structs for product info
- File persistence
- Enum for category (ELECTRONICS, FOOD, CLOTHING)
Features #
- Add/Remove items
- Search by name
- Generate invoice file
๐งฉ Project 3: Library Management System #
Description #
Manage a small digital library database.
Key Concepts #
- Linked list of books (dynamic allocation)
- Struct with nested structs (Book, Author)
- File I/O to store data between runs
Features #
- Add/Remove/Search books
- Issue/Return functionality
- Save state to
library.dat
๐งฎ Project 4: Matrix Operations Toolkit #
Description #
Write a program to handle matrix operations (addition, multiplication, transpose, determinant).
Key Concepts #
- 2D dynamic arrays (pointer to pointer)
- Functions that allocate and free matrices
- Error checking for dimensions
Bonus #
- Include file-based input/output for matrices.
๐ง Project 5: Quiz Game with Leaderboard #
Description #
A text-based quiz game that reads questions from a file, accepts answers, and maintains a leaderboard.
Key Concepts #
- File I/O for question bank and leaderboard
- Struct for player data
- Enum for difficulty level
Features #
- Add questions via file
- Randomize question order
- Save top 5 scores
๐งโ๐คโ๐ง Project 6 โ Mini Social Network #
๐ฏ Goal #
Simulate a simple social network using structs, pointers, and dynamic memory.
๐งฉ Key Concepts #
- Dynamic memory (
malloc,realloc,free) - Structs with pointer fields
- Recursion for โfriends-of-friendsโ
- File persistence
- Bidirectional relationships
๐๏ธ Example Structures #
typedef struct Person {
char name[30];
struct Person** friends;
int num_friends;
} Person;
๐งพ Features #
- Add new people
- Add friendships (bi-directional links)
- Print network connections
- Save / load network from file
๐ก Example Run #
Enter name: Alice
Enter name: Bob
Make friends? (Alice, Bob): y
Friendship created!
Aliceโs friends: Bob
Bobโs friends: Alice
๐ช Project 7 โ Store Receipt Management System #
๐ฏ Goal #
Create a store checkout and receipt generator that stores items, computes totals, and saves transactions.
๐งฉ Key Concepts #
- Structs for product, cart item, and receipt
- Enums for product category
- Dynamic arrays for cart items
- File I/O for saving receipts
๐๏ธ Example Structures #
typedef enum {
GROCERY,
ELECTRONICS,
CLOTHING
} Category;
typedef struct {
int id;
char name[50];
float price;
Category type;
} Product;
typedef struct {
Product *product;
int quantity;
} CartItem;
typedef struct {
int receipt_id;
CartItem *items;
int item_count;
float total;
} Receipt;
๐ป Features #
- Add products
- Display catalog
- Add to cart dynamically
- Generate and print receipts
- Save receipts to file
๐พ Example Output #
===== STORE MENU =====
1. Add product
2. Purchase
3. Print receipt
4. Exit
Product: Milk
Qty: 2
Total: 91.00
Receipt saved to receipts.txt
๐ง Project 8 โ ATM Transaction System #
๐ฏ Goal #
Simulate an ATM machine where users can create accounts, deposit, withdraw, and view transaction history.
๐งฉ Key Concepts #
- Structs and enums
- Dynamic transaction list
- File I/O for persistence
- Secure PIN check
๐๏ธ Example Structures #
typedef enum {
DEPOSIT,
WITHDRAWAL,
BALANCE_CHECK
} TransactionType;
typedef struct {
TransactionType type;
float amount;
char timestamp[30];
} Transaction;
typedef struct {
int account_number;
char name[50];
int pin;
float balance;
Transaction* history;
int transaction_count;
} Account;
๐ป Features #
- Create account
- Login with PIN
- Deposit / Withdraw
- Show balance and transactions
- Save all data to file
๐งพ Example Output #
=== ATM SYSTEM ===
1. Create Account
2. Login
3. Exit
Account created: Alice (Acc #1001)
Deposit 500 โ Balance = 500.00
Withdraw 100 โ Balance = 400.00
Project 9 - Fractals #
Read about Fractals, Madelbrot Set and BMP image format:
- https://en.wikipedia.org/wiki/Fractal.
- https://en.wikipedia.org/wiki/Mandelbrot_set
- https://en.wikipedia.org/wiki/BMP_file_format
Understand the code for generating a BMP image of Madelbrot Set Fractal here: madelbrot. There are also several exercises given in the comments, including modifying the code to generate the Julia set, which you can try.
Modularize the code, by splitting it into several files/folders and have a makefile.
Project 10: Image editor #
Learn about the PPM image format and complete the exercises in the code: image editor.
Also modularize the code by splitting it into headers, .c files, include, src folder and add makefile.
Project 11 - Jon Conway’s Game of Life #
Read about John Conway’s Game of life:
Complete the c code implementing it here: gameoflife.c
๐๏ธ Submission & Documentation Checklist #
1. Cover Page #
Include title, student details, course name, instructor name, and date.
2. Project Report (3โ5 pages) #
Recommended Sections #
- Introduction
- Design and Approach
- Implementation Details
- Testing and Results
- Conclusion and Future Work
3. Source Code Folder #
.cfiles and aMakefile- Use header files for modularity
- Compile with
gcc -Wall -Wextra
4. README File #
- Compilation and execution instructions
- Input/output format description
- Example runs
5. Example Input/Output Files #
Include at least 3 test cases:
- Small, medium, and edge-case dataset.
6. Evaluation Rubric #
| Criteria | Description | Marks |
|---|---|---|
| Correctness | Program compiles and meets requirements | 30 |
| Memory Handling | Proper use of malloc/free, no leaks | 15 |
| Structs/Enums | Modular and clean design | 15 |
| File I/O | Robust input/output | 10 |
| Code Quality | Comments, naming, readability | 10 |
| Testing & Documentation | Examples, explanations | 20 |
| Total | 100 |
๐ก Tip: Always run your code through Valgrind to check for memory leaks before submission!