Chinmay Dabke
Chinmay Dabke

Reputation: 5140

Use a text file for bank program in C

i have almost completed this bank program with your help(i had asked a question on the same code earlier).But i want to link the bank account user's number and his balance in this C code with a text file. I don't know whether it is possible or not as i am new to programming. I saw the rest of the related questions on this site and thus i asked this one. Thank you!

#include<stdio.h>
#include<conio.h>
int main(void)
{
int deposit,withdraw,kbalance;
int option;
int decash,wicash;
int balance;
int wibal;

printf("Wel0ome to skybank\n");
printf("Enter your current Balance\n");
scanf_s("%d", &balance);
printf("Press 1 to deposit cash\n");
printf("Press 2 to Withdraw Cash\n");
printf("Press 3 to Know Your Balance\n");
printf("Press 4 to Quit\n");
while((option=getchar())!=4){
scanf_s("%d", &option);
switch(option)
   {
    case 1:
        printf("Enter the amount you want to deposit\n");
        scanf_s("%d", &decash);
        printf("Thank You\n");
        printf("%d have been deposited in your account\n", decash);
        balance=balance+decash;
        printf("Your balance is Rs.%d\n",balance);
        break;
    case 2:
        printf("Enter the amount you want to withdraw\n");
        scanf_s("%d", &wicash);
        wibal=balance-wicash;
        if(wicash<balance){
            printf("Thank You\n");
            printf("%d have been withdrawed from your account\n", wicash);
            printf("Your balance is Rs.%d\n", wibal);}
        else{
            printf("Sorry. You have insufficient balance to conduct         this transaction!\n");}
        balance=balance-wicash;
        break;
    case 3:
        printf("Your balance is Rs.%d\n", balance);
        break;
    case 4:
        exit();
        break;
    default:
        printf("Invalid Input\n");
        break;
    }
}
_getch();
}

Upvotes: 3

Views: 2553

Answers (2)

Varda Elent&#225;ri
Varda Elent&#225;ri

Reputation: 2322

of course you can do that!

Just familiarize your self with dealing with dealing with files in C. Here's a good tutorial http://www.tutorialspoint.com/ansi_c/c_working_with_files.htm

Upvotes: 2

hazzelnuttie
hazzelnuttie

Reputation: 1481

Have a structure

struct BankAccount
{
    int AccountNo;
    int Balance
} Accounts[NUM_OF_ACCOUNTS]

Read/Write to file using structure format

Upvotes: 2

Related Questions