π° Banking System in C (With File Handling) – Complete Project
π· Introduction
In this project, we will build a Banking System in C Programming that allows users to manage bank accounts efficiently.
This system enables users to create accounts, deposit money, withdraw money, and check account details using file handling.
π This is an advanced-level project that demonstrates real-world use of C programming concepts.
π· π Project Preview
Menu-driven banking system
Stores account data in file
Secure deposit and withdrawal logic
Continuous user interaction
π· π Project Flow
User
↓
Menu
↓
Select Operation
↓
Process Request
↓
Update File
↓
Display Result
π· ✨ Features
π Create Account
π΅ Deposit Money
πΈ Withdraw Money
π Check Balance
π View All Accounts
❌ Exit
π· π§ Concepts Used
Structures
File Handling
Functions
Conditional Statements
Loops
π· π Related Topics (Learn More)
Before working on this project, you should understand:
Structures in C
File Handling in C
Functions in C
These concepts are essential for building this system.
π· π‘ Real-World Use
Used in banking systems to manage customer accounts
Helps in handling financial transactions securely
Basis for ATM and online banking systems
Used in financial software for account management
Demonstrates how real systems store and process data
π· ⭐ Important Note
This project is very important for exams, practicals, and interviews.
It is commonly asked as a major programming assignment.
π· π» Program Code (With Comments)
#include <stdio.h> // For input/output functions (printf, scanf)
#include <stdlib.h> // For exit() function
// Structure for bank account
struct account {
int accNo; // Stores account number
char name[50]; // Stores account holder name
float balance; // Stores account balance
};
// Create account
void createAccount() {
FILE *fp = fopen("bank.txt", "a"); // Open file in append mode
struct account a; // Create structure variable
printf("Enter Account Number: "); // Ask for account number
scanf("%d", &a.accNo); // Read account number
printf("Enter Name: "); // Ask for name
scanf(" %[^\n]", a.name); // Read full name with spaces
printf("Enter Initial Balance: "); // Ask for initial balance
scanf("%f", &a.balance); // Read balance
fwrite(&a, sizeof(a), 1, fp); // Write structure data to file
fclose(fp); // Close file
printf("✅ Account created successfully!\n"); // Success message
}
// View all accounts
void viewAccounts() {
FILE *fp = fopen("bank.txt", "r"); // Open file in read mode
struct account a; // Structure variable
printf("\n--- Account Details ---\n"); // Heading
while(fread(&a, sizeof(a), 1, fp)) { // Read until end of file
printf("Acc No: %d | Name: %s | Balance: %.2f\n", a.accNo, a.name, a.balance); // Display details
}
fclose(fp); // Close file
}
// Deposit money
void deposit() {
FILE *fp = fopen("bank.txt", "r+"); // Open file for read & write
struct account a; // Structure variable
int acc; // Variable for account number
float amount; // Variable for deposit amount
printf("Enter Account Number: "); // Ask for account number
scanf("%d", &acc); // Read account number
while(fread(&a, sizeof(a), 1, fp)) { // Search account in file
if(a.accNo == acc) { // If account found
printf("Enter amount to deposit: "); // Ask amount
scanf("%f", &amount); // Read amount
a.balance += amount; // Add amount to balance
fseek(fp, -sizeof(a), SEEK_CUR); // Move pointer back
fwrite(&a, sizeof(a), 1, fp); // Update record
printf("✅ Amount deposited successfully!\n"); // Success
return; // Exit function
}
}
printf("❌ Account not found!\n"); // If not found
fclose(fp); // Close file
}
// Withdraw money
void withdraw() {
FILE *fp = fopen("bank.txt", "r+"); // Open file for read & write
struct account a; // Structure variable
int acc; // Account number
float amount; // Withdrawal amount
printf("Enter Account Number: "); // Ask account number
scanf("%d", &acc); // Read input
while(fread(&a, sizeof(a), 1, fp)) { // Search account
if(a.accNo == acc) { // If found
printf("Enter amount to withdraw: "); // Ask amount
scanf("%f", &amount); // Read amount
if(a.balance >= amount) { // Check balance
a.balance -= amount; // Deduct amount
fseek(fp, -sizeof(a), SEEK_CUR); // Move pointer back
fwrite(&a, sizeof(a), 1, fp); // Update record
printf("✅ Withdrawal successful!\n"); // Success
} else {
printf("❌ Insufficient balance!\n"); // Error
}
return; // Exit function
}
}
printf("❌ Account not found!\n"); // If account not found
fclose(fp); // Close file
}
// Check balance
void checkBalance() {
FILE *fp = fopen("bank.txt", "r"); // Open file in read mode
struct account a; // Structure variable
int acc; // Account number
printf("Enter Account Number: "); // Ask account number
scanf("%d", &acc); // Read input
while(fread(&a, sizeof(a), 1, fp)) { // Search account
if(a.accNo == acc) { // If found
printf("Balance: %.2f\n", a.balance); // Show balance
return; // Exit function
}
}
printf("❌ Account not found!\n"); // If not found
fclose(fp); // Close file
}
// Main function
int main() {
int choice; // Variable for menu choice
while(1) { // Infinite loop
printf("\n===== Banking System =====\n"); // Title
printf("1. Create Account\n"); // Option 1
printf("2. View Accounts\n"); // Option 2
printf("3. Deposit\n"); // Option 3
printf("4. Withdraw\n"); // Option 4
printf("5. Check Balance\n"); // Option 5
printf("6. Exit\n"); // Option 6
printf("Enter your choice: "); // Ask choice
scanf("%d", &choice); // Read choice
switch(choice) { // Switch case
case 1: createAccount(); break; // Call create
case 2: viewAccounts(); break; // Call view
case 3: deposit(); break; // Call deposit
case 4: withdraw(); break; // Call withdraw
case 5: checkBalance(); break; // Call check balance
case 6: exit(0); // Exit program
default: printf("❌ Invalid choice!\n"); // Wrong input
}
}
return 0; // End program
}
π· ▶️ How to Run the Program
Open any C compiler (GCC / CodeBlocks / Turbo C)
Copy and paste the code
Compile the program
Run the executable
Use menu options to perform operations
π· π File Storage Explanation
Data is stored in bank.txt
Uses binary file handling (fwrite, fread)
Data remains saved permanently
π· π₯ Sample Output
===== Banking System =====
1. Create Account
2. View Accounts
3. Deposit
4. Withdraw
5. Check Balance
6. Exit
π· π§ Deep Explanation
This project uses file handling to store account data permanently. Each account is saved in a file using binary format.
For deposit and withdrawal, the program searches the account in the file. Once found, it updates the balance using file pointer repositioning (fseek).
The system ensures correct transaction handling by checking balance before withdrawal.
π· π Future Improvements
Add password protection
Transaction history
Interest calculation
GUI-based banking system
π· π Conclusion
This Banking System project demonstrates how real-world applications manage financial data using C programming. It strengthens your understanding of file handling and logical problem-solving.
⭐ Tip: Try adding more features to make your own advanced banking system!
π Keep Learning. Keep Coding. Keep Growing.
✨ Written by Krishna Popat
π± Founder, Learning Growth Hub
Comments
Post a Comment