Mini project
Bank Account Management System in C
A menu-driven C program that creates bank accounts, handles deposits, withdrawals and transfers with balance checks, keeps a transaction history, and stores records in a binary file.
CstructsFile handlingGCC
The problem
A bank needs to keep every customer's balance correct after each transaction and never lose records when the program stops. This is a popular first-year project because it uses most of the C basics together: structs, functions, loops, strings and files.
Features to build
- Create an account with an automatically generated account number, name and opening balance
- Deposit and withdraw money, rejecting negative amounts and withdrawals larger than the balance
- Transfer money between two accounts
- Show account details and a mini statement of the last transactions
- Search an account by number and close an account
- Save all accounts to a binary file and load them when the program starts
Suggested data model
struct Account {
int number;
char name[50];
double balance;
int active; /* 1 = open, 0 = closed */
};
struct Transaction {
int account;
char type; /* 'D' deposit, 'W' withdrawal, 'T' transfer */
double amount;
long timestamp;
};Build plan
- 1
Define the structs and the menu
Write the Account struct and a do-while loop with a switch for each menu option.
- 2
Create and find accounts
Keep accounts in an array, generate the next account number from the highest used, and write a find function that returns the index or -1.
- 3
Deposit, withdraw and transfer
Write one function for each, with checks for invalid amounts and low balance. Pass the account by pointer so the function can change the balance.
- 4
Save and load with binary files
Use fopen with wb and rb, and fwrite and fread for the whole array. Check every fopen result for NULL.
- 5
Input safety
Check the return value of scanf, and read names with fgets so long names do not overflow the array.
- 6
Test and document
Test withdrawals of exactly the balance, transfers to the same account and closed accounts. Write a README with how to compile with gcc.
Learn these first
Each part of the project is taught in one of these free lessons.
- Structures in C: struct, typedef, Arrays of Structs and Pointers to Structs
- Functions in C: Declaration, Definition, Prototypes and Calling
- Pointers and Functions in C: Output Parameters, Returning Pointers and Function Pointers
- Strings in C: char Arrays, the Null Terminator and Reading Text Safely
- switch Statement in C: case, break, default and Fall-through
- File Handling in C: fopen, fprintf, fgets, fread, fwrite and fclose
- Input and Output in C: printf, scanf, fgets and Format Specifiers
- Header Files and Multi-file Programs in C: .h and .c Files, Linking and Makefiles
Make it stand out
- A 4-digit PIN for each account, checked before withdrawals
- Monthly interest for savings accounts
- Store transactions in their own file, with date and time from time.h
- Split the program into several .c and .h files
Viva and interview questions
Try to answer each one aloud before you open it.
Why did you use a struct?
An account has several related values: number, name and balance. A struct keeps them together as one variable, so I can store accounts in an array and pass one account to a function.
Why do you pass the account to deposit() as a pointer?
C passes arguments by value. With a pointer, the function changes the original account's balance instead of a copy.
What is the difference between a text file and a binary file here?
A binary file stores the struct's bytes exactly as they are in memory, so
fwriteandfreadsave and load whole records quickly. A text file is human-readable but needs formatting and parsing.How do you stop a user from withdrawing more than the balance?
Before changing the balance, the withdraw function checks that the amount is positive and not greater than the balance. If not, it prints a message and returns without changing anything.
Why is double not ideal for money in real banks?
Floating-point numbers cannot store many decimal values exactly, so small rounding errors can appear. Real systems store money as whole paise in an integer type, or use decimal types.
What to put in your project report
- Abstract: the problem, your solution and the result in one paragraph.
- Introduction and problem statement: who has the problem and why it matters.
- Requirements: the features (functional) and qualities such as speed and security (non-functional).
- Design: architecture diagram, database tables or data flow, and screen layouts.
- Implementation: the main modules and the most interesting code, explained.
- Testing: the test cases you ran, with inputs, expected and actual results.
- Results: screenshots or numbers that show the project working.
- Conclusion and future scope: what you achieved and what you would add next.
Your college may give its own format. Follow that first, and use this list to check nothing is missing.