| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:关于文件读写的问题
只看楼主 加入收藏
恋樱InG
Rank: 1
来 自:中国
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-2-3
收藏
 问题点数:0 回复次数:0 
关于文件读写的问题
我想要做一个关于银行管理的程序,该程序将会包含创建用户,更改用户存款的功能.
其中用户的结构体有如下定义:
struct inf
{
    long cardnumber;
    long password;
    char fname[21];
    char lname[21];
    float money;   
};   
创建用户的功能已经编好,如下代码:
void create(void)
{
    FILE *fp;
    fp=fopen(fp,"a+b");
    auto struct user;
    auto flag=0;
    auto char answer;
    while(flag==0)
    {
        create_menu();
        user.cardnumber=create_cardnumber();
        user.password=create_password
        gotoxy(1,22);
        printf("Please enter your first name:");
        gets(user.fname);
        printf("Please enter your last name:");
        gotoxy(1,22);
        gets(user.lname);
        user.money=get_money();
        gotoxy(1,22);
        printf("Name:%s %s",user.fname,user.lname);
        gotoxy(1,22);
        printf("Cardnumber:%ld",user.cardnumber);
        gotoxy(1,22)
        printf("Password:%ld",user.password);
        gotoxy(1,22);
        printf("Money:.4f",user.money);
        gotoxy(1,25);
        printf("Are you sure?(Y or y to continue,q to quit)");
        if(answer=getchar()!='Y'&&answer=getchar()!='y'
            &&answer=getchar()!='Q'&&answer!='q')
            system("cls");
        else if(answer=getchar()=='Y'&&answer=getchar()=='y')
        {
            fwrite(&user,sizeof(struct inf),1,fp);
            flag=1;
        }
        else
            break;
    }
    fclose(fp);
    system("cls");
    if(flag==1)
    {
        gotoxy(6,22);
        printf("You have successfully created a new user.\n");
    }
    else
    {
        gotoxy(6,22);
        printf("You fail to create a new user.\n");
    }
}
而用户的登陆及修改特定用户的资料时,却无从下手,我的程序只完成到这,,代码如下:
int login(void)
{
    FILE *fp;
    extern struct inf user,
    auto struct inf temp;
    auto int flag=0;
    auto int size=sizeof(struct inf);
    fp=fopen("data","rb");
    rewind(fp);
    while(flag==0)
    {
        login_menu();
        temp.cardnumber=get_cardnumber();
        temp.password=get_password();
        if((user.cardnumber==temp.cardnumber)&&
            (user.password==temp.password))
            flag=1;
        else if(fseek(fp,ptr,CUR)!=0)
            break;
        else
               
    }
}
void inquiry(FILE *fp,struct inf *pst)
{
    gotoxy(4,25);
    printf("Welcome to China Construction Bank");
    gotoxy(1,22);
    printf("Name:%s %s",pst->fname,pst->lname);
    gotoxy(1,22);
    printf("Cardnumber:%ld",pst->cardnumber);
    gotoxy(1,22);
    printf("Money:%.4f",pst->money);
}
void despoit(FILE *fp,struct inf *pst)
{
    auto int money;
    gotoxy(4,25);
    printf("Welcome to China Construction Bank");
    gotoxy(1,22);
    printf("How much do yo want to despoit?\n");
    while(scanf(".4f",&money!=1))
    {
        gotoxy(1,22);
        printf("You may enter an invalid money.");
        gotoxy(1,22);
        printf("How much do yo want to despoit?\n");
    }
    pst->money+=money;
}
void teller(FILE *fp,struct inf *pst)
{
    auto int money;
    gotoxy(4,25);
    printf("Welcome to China Construction Bank");
    gotoxy(1,22);
    printf("How much do yo want to teller?\n$");
    while(scanf(".4f",&money!=1)&&money>(pst->money))
    {
        if(scanf(".4f",&money!=1))
        {
            gotoxy(1,22);
            printf("You may enter an invalid money.");
        }
        else
        {
            gotoxy(1,22);
            printf("You don't have enough money.");
        gotoxy(1,22);
        printf("How much do yo want to despoit?\n");
    }
    pst->money-=money;
}
希望高手能帮助一下
搜索更多相关主题的帖子: long void password 银行管理 create 
2012-02-06 14:53
快速回复:关于文件读写的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028935 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved