Skip to content
C project #22Advanced

Banking Management System

Multiple savings/current accounts, hashed PINs, transfers, interest credit, an append-only transaction log and statements — with money stored in paise.

Estimated time
~10 hours to build
Files
7 files · 607 lines
Technologies
C11, <stdint.h>, Binary file I/O

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

Open savings (minimum balance Rs 1,000) and current accounts with a 4-digit PIN; deposit; withdraw and transfer with PIN checks and balance rules; credit simple interest to savings accounts; print a statement of the last 10 transactions from an append-only log; and print a bank-wide report. Data must survive restarts and never be half-written.

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.

TextArchitecture diagram
main.c ─> bank.c ─┬─> accounts.dat (current balances, rewritten safely)
└─> transactions.log (append-only history)

Folder structure

TextProject tree
banking-management-system/
├── README.md
├── Makefile
├── src/bank.c
├── src/bank.h
├── src/main.c
├── tests/expected-output.txt
└── tests/sample-input.txt

Complete source code

Makefile

20 lines
MakefileMakefile
# Generated for KENHOLT Skills. Usage: make | make test | make clean
CC = gcc
CFLAGS = -std=c11 -Wall -Wextra -O2
SRC := $(wildcard src/*.c)
HDR := $(wildcard src/*.h)
ARGS := $(shell cat tests/args.txt 2>/dev/null)
INPUT := $(wildcard tests/sample-input.txt)
app: $(SRC) $(HDR)
$(CC) $(CFLAGS) -Isrc $(SRC) -o app -lm
test: app
./app $(ARGS) $(if $(INPUT),< $(INPUT),) > actual.txt
diff actual.txt tests/expected-output.txt && echo "Test passed: output matches tests/expected-output.txt"
clean:
rm -f app app.exe actual.txt
.PHONY: test clean

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: make builds ./app, make test runs the sample session and compares it with the expected output, make clean removes build files.

How to run it

Build

Terminal
gcc -std=c11 -Wall -Wextra -Isrc src/*.c -o app -lm
# or simply: make

Run

Terminal
./app # Linux / macOS
.\app.exe # Windows

Test against the expected output

Terminal
./app < tests/sample-input.txt > actual.txt
diff actual.txt tests/expected-output.txt # no output means they match
# Windows PowerShell:
# Get-Content tests\sample-input.txt | .\app.exe > actual.txt
# Compare-Object (Get-Content actual.txt) (Get-Content tests\expected-output.txt)

Expected output

Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.

Texttests/expected-output.txt
=== KENHOLT Bank - branch console ===
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Holder name:
Type (S)avings or (C)urrent, PIN, opening amount:
Account 50010001 opened for Asha Rao.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Holder name:
Type (S)avings or (C)urrent, PIN, opening amount:
Account 50010002 opened for Vikram Traders.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Holder name:
Type (S)avings or (C)urrent, PIN, opening amount:
Cannot open account: invalid amount (savings accounts need Rs 1000.00 to open).
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Account and amount:
Deposited. Balance Rs 7500.50.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Account, PIN and amount:
Withdrawal failed: incorrect PIN.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Account, PIN and amount:
Withdrawal failed: insufficient funds.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Account, PIN and amount:
Withdrawn. Balance Rs 6000.25.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
From account, PIN, to account, amount:
Transfer complete.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
From account, PIN, to account, amount:
Transfer failed: cannot transfer to the same account.
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Account and PIN:
Vikram Traders, account 50010002: Rs 2000.00
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Annual rate (%) and number of days:
Interest credited to 1 savings account(s).
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Account and PIN:
Seq Type Amount Balance Counterparty
1 OPEN 5000.00 5000.00
3 DEPOSIT 2500.50 7500.50
4 WITHDRAW 1500.25 6000.25
5 TRANSFER OUT 2000.00 4000.25 50010002
7 INTEREST 13.15 4013.40
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Account Holder Type Balance
50010001 Asha Rao Savings 4013.40
50010002 Vikram Traders Current 2000.00
2 account(s), total deposits Rs 6013.40
1.Open account 2.Deposit 3.Withdraw 4.Transfer 5.Balance 6.Statement 7.Credit interest 8.Bank report 0.Exit
Choice:
Data saved. Goodbye.
Input
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

  1. 1Verify that replaying transactions.log reproduces every balance (an audit check).
  2. 2Replace FNV-1a with a salted, iterated hash and explain why that is stronger.
  3. 3Add daily transfer limits that reset by date.

Built and tested it yourself? Mark it to update your dashboard.