A robust, memory-safe command-line personal finance manager written entirely in C.
This project was built to demonstrate core computer science principles, including manual dynamic memory management, defensive programming, and binary file I/O operations.
- Dynamic Memory Allocation: Uses
mallocandreallocto scale the transaction list infinitely while shrinking arrays upon deletion to conserve RAM. - Defensive Programming: Strict input validation utilizing
strtolandstrtodto prevent crashes from invalid data types, alongside safeguards against corrupted binary data files. - Binary File Persistence: Fast, automated saving and loading of structs directly to/from disk using
fwriteandfread. - Custom QuickSort: Manually implemented recursive QuickSort algorithm to order transactions by date or amount.
- Data Analysis: Generates calculated monthly summaries isolating net balances.
cli-expense-tracker/
├── .github/
│ └── workflows/
│ └── make.yml # "C/C++ CI with Make" workflow
├── src/
│ ├── main.c # Application loop and interactive menu
│ ├── transaction.c # Data models, QuickSort, and array management
│ ├── storage.c # Binary File I/O operations
│ └── utils.c # Safe string parsing and validation wrappers
├── data/
│ └── transactions.dat # Auto-generated binary storage file
└── Makefile # Compilation instructions
Prerequisites: You must have a C compiler (like gcc) and make installed on your system.
-
Clone the repository:
git clone https://github.com/samybit/cli-expense-tracker.git cd cli-expense-tracker -
Compile the project using the provided Makefile:
make
-
Run the executable:
./expense_tracker
Upon running ./expense_tracker, you will be greeted with an interactive terminal menu.
Adding a Transaction:
Choose an option: 1
Enter date (YYYY-MM-DD): 2026-02-24
Enter amount: 150.50
Enter type (0 for INCOME, 1 for EXPENSE): 1
Enter category: Groceries
Enter description: Weekly food shopping
Transaction added successfully!
Viewing the Monthly Summary:
Choose an option: 4
Enter Year (e.g., 2023): 2026
Enter Month (1-12): 2
--- Summary for 2026-02 ---
Date | Amount | Type | Category
----------------------------------------------------
2026-02-24 | 150.50 | EXPENSE | Groceries
----------------------------------------------------
Total Income: +0.00
Total Expense: -150.50
Net Balance: -150.50
----------------------------------------------------
To remove the compiled object files and the executable, run:
make clean(Note: This will not delete your saved transactions.dat data file).