Introduction
Banking software must never lose a rupee, never store secrets in plain text and always be able to explain a balance. This project applies those principles: integer money, hashed PINs, atomic updates and an audit log.
Problem statement
Objectives
- Represent money exactly with integer paise
- Store a hash of a secret instead of the secret
- Keep a separate append-only audit log
- Write files safely with write-then-rename
Features
- Savings and current accounts with different rules
- FNV-1a hashed PINs
- Deposits, withdrawals and transfers with validation
- Interest credit
- Statements from the transaction log
- Crash-safe saving
Concepts demonstrated
- Fixed-point money
- Hashing
- Audit logs
- Atomic file replacement
- Error enums
System architecture
bank.c keeps accounts in memory and saves them to accounts.dat (via a .tmp file and rename). Every successful change appends a Transaction record to transactions.log, which is never rewritten. Operations return a BankStatus enum; bank_status() turns it into a message. Amounts are parsed from text like 1250.50 straight into paise, avoiding floating point.
Folder structure
Complete source code
Makefile
What each file does
- src/bank.h
- Account and transaction types, status codes and the API.
- src/bank.c
- PIN hashing, rules for each operation, interest, the transaction log, statements, reports and persistence.
- src/main.c
- Exact rupee/paise parsing and the branch console menu.
- Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
1 Asha Rao S 1234 5000 1 Vikram Traders C 4321 0 1 Small Saver S 1111 500 2 50010001 2500.50 3 50010001 9999 100 3 50010001 1234 7000 3 50010001 1234 1500.25 4 50010001 1234 50010002 2000 4 50010002 4321 50010002 10 5 50010002 4321 7 4 30 6 50010001 1234 8 0
Testing
- Diff with
tests/expected-output.txt(wrong PIN, insufficient funds, a same-account transfer and interest of Rs 13.15). - Check the interest by hand: 4000.25 × 4% × 30/365 = 13.15.
- Restart and print a statement — history must persist.
Common errors
Balances off by one paisa
Never convert money through float or double; parse input directly into integer paise.
accounts.dat corrupted after a crash
Write to accounts.dat.tmp and rename it over the original only after a successful close.
Possible improvements
- Lock accounts after three wrong PINs
- Fixed deposits and loans
- Monthly statements as text files
Additional challenges
- 1Verify that replaying transactions.log reproduces every balance (an audit check).
- 2Replace FNV-1a with a salted, iterated hash and explain why that is stronger.
- 3Add daily transfer limits that reset by date.
Built and tested it yourself? Mark it to update your dashboard.