πŸ’° 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

  1. Open any C compiler (GCC / CodeBlocks / Turbo C)

  2. Copy and paste the code

  3. Compile the program

  4. Run the executable

  5. 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

Popular posts from this blog

🌟 The Honest Journey of a Student: Learning, Failing, and Growing

“C Programming for Beginners: Master Variables, Data Types, and Memory (Bits Explained)”