繁体   English   中英

在C中使用银行程序的文本文件

[英]Use a text file for bank program in C

我已经在你的帮助下差不多完成了这个银行程序(我之前就相同的代码问了一个问题)。但我想用这个C代码将银行帐户用户的号码和余额与文本文件联系起来。 我不知道是否可能,因为我是编程的新手。 我在这个网站上看到了其他相关问题,因此我问了这个问题。 谢谢!

#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();
}

有一个结构

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

使用结构格式读/写文件

当然你可以做到!

让自己熟悉处理C语言中的文件。这是一个很好的教程http://www.tutorialspoint.com/ansi_c/c_working_with_files.htm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM