| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 987 人关注过本帖
标题:借书模块 直接报错 求大佬帮忙
取消只看楼主 加入收藏
我们0620
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-30
结帖率:0
收藏
 问题点数:0 回复次数:1 
借书模块 直接报错 求大佬帮忙
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
//定义一个学生的结构体类型
typedef struct book
{
    char name[20];
   
    char sbm[30];//书本名
    int id;
    float price;
    int tsbh;//图书编号
    int sjl;//书籍量
   struct book *next;
}STU;
typedef struct lent
{
    char lent_sbm[30];
    int lent_tsbh;
    int lent_sjl;
    float lent_price;
    char lent_name[20];
    char lent_dz[20];
    int lent_bh;
    int lent_dh;
    struct lent *next;
}LENT;
typedef struct dz
{
    char mz[30];//名字
    int bh;//身份证件号
    int dh;//电话号码
    struct dz *next;
}DZ;//读者

int menu();
DZ *Nodelist();
STU *CreatList();
void List(STU *head);
void List1(DZ *head1);
void List2(LENT *head2);
void Delxm(STU *head,char delxm[]);
void Addxm(STU *head);
void cz(STU *head);
void ADDxs(DZ *head1);
void Fwrite2(LENT *head2);
LENT *Fread2();
void Fwrite(STU *head);
LENT *Kai();
STU *Fread();
void Fwrite1(DZ *head1);
DZ *Fread1();
void Delxs(DZ *head1,char delxs[]);
void Lend(STU *head,DZ *head1,LENT *head2);
void Return(LENT *head2);
int main(int argc,char *argv){
    int i,choose,rs,xm,xh,pxx,pxx1;
    char sbm[30];
    char xsmz[20];//学生名字
    STU *tou;
    DZ *tou1;
    LENT *tou2;
    tou=Fread();
    tou1=Fread1();
    tou2=Fread2();
    while(1){
        switch(choose=menu()){
        case 1:tou=CreatList();break;
        case 2:{
        
        List(tou);}break;
        case 3:{
            
            puts("请输入删除的书本名:");
            getchar();
            gets(sbm);
            Delxm(tou,sbm);
               }break;
        case 4:tou1=Nodelist();break;
        case 5:List1(tou1);break;//dzxx:读者信息                                                                                       
        case 6:{
            Addxm(tou);
               }break;   
        case 7:{
               ADDxs(tou1);
               }break;
        case 8:Lend(tou,tou1,tou2);break;
        case 9:{
            printf("请输入删除学生的名字:");
            getchar();
            gets(xsmz);
            Delxs(tou1,xsmz);
               }break;

        case 10:List2(tou2);break;
        case 11:tou2=Kai();break;
        case 12:{cz(tou);
               }break;
        case 13:Return(tou2);break;
        case 0:exit(0);
        default :puts("error!");
        }        
    }
    return 0;
}
DZ *Nodelist()         //录入学生信息
{
    DZ *head1,*end1,*r1;
    int num;
    head1=(DZ *)malloc(sizeof(DZ));
    end1=head1;
    end1->next=NULL;
    while(1)
    {
        r1=(DZ *)malloc(sizeof(DZ));
        getchar();
        puts("请输入姓名:");
        gets(r1->mz);
        puts("请输入读者身份证件号:");
        scanf("%d",&r1->bh);
        puts("请留个电话号码:");
        scanf("%d",&r1->dh);
        end1->next=r1;
        end1=r1;
        printf("\n录入完成");
        printf("\n如果继续录入请按 1");
        printf("\n如果退出请按其他数字:");
        scanf("\n%d",&num);
        if(num!=1)
        {
            break;
        }
   
    }

end1->next=NULL;
Fwrite1(head1);
return head1;

}
STU *CreatList(){                             //输入书本信息
    STU *head,*end,*r;
    int i,num;
   
    head=(STU *)malloc(sizeof(STU));
    end=head;
    end->next=NULL;               //初始化
    printf("请输入要录入的书本数量:");
    scanf("%d",&num);
    for(i=0;i<num;i++)
    {
        r=(STU *)malloc(sizeof(STU));//存后面的人
            
        B:{getchar();                        
        puts("输入书本名:");
        gets(r->sbm);
        puts("输入作者:");
        gets(r->name);
        puts("请输入价格: ");
        scanf("%f",&r->price);
        getchar();
        puts("输入图书编号:");
        scanf("%d",&r->tsbh);
        puts("请输入书籍量: ");
        scanf("%d",&r->sjl);
        puts("                ");}
        end->next=r;      //开辟下一个
        end=r;
               
    }

    end->next=NULL; //结束空间开辟
    Fwrite(head);
    return head;
        
   
    }
void List1(DZ *head1)     //输出读者信息
{    DZ *pxx1;
    head1=Fread1();

    pxx1=head1->next;
 
    while(pxx1!=NULL)
    {
        printf("\t姓名\t身份证件号\t\t电话号码\n");
        printf("\t%s\t%d\t\t\t%d\n",pxx1->mz,pxx1->bh,pxx1->dh);
        printf("            \n");
        pxx1=pxx1->next;
        
    }
    printf("   ");
   
    Fwrite1(head1);
    return head1;
}
void List(STU *head){//输出书本信息
   
    STU *pxx;
    head=Fread();
    pxx=head->next;   
        printf("\t书本名\t作者\t价格\t图书编号\t书籍量\n");
    while(pxx!=NULL){
        printf("\t%s\t%s\t%.2f\t%d\t\t%d\n",pxx->sbm,pxx->name,pxx->price,pxx->tsbh,pxx->sjl);

                   pxx=pxx->next;
        }
        
        Fwrite(head);
        return head;
}

void List2(LENT *head2)
{
   
    LENT *p;
    head2=Fread2();
    p=head2->next;
    printf("\t\t*****读者借阅信息*****\n");
    printf("\n\t读者\t电话号码\t图书名称\t\t图书编号\t图书价格\t身份证号码\n");
    while(p!=NULL)
    {
        printf("\t%s\t%d\t\t%s\t\t\t%d\t\t%.2f\t\t%d\n",p->lent_dz,p->lent_dh,p->lent_sbm,p->lent_tsbh,p->lent_price,p->lent_bh);
        p=p->next;
    }
    return head2;
}
void Delxs(DZ *head1,char delxs[20])      //删除学生
    {
        DZ *pxx1,*pxxq1;
        pxxq1=head1;
        pxx1=pxxq1->next;
        while(pxx1!=NULL)
        {
            if(strcmp(pxx1->mz,delxs)==0)
            {
                printf("姓名:%s\n编号:%d\n",pxx1->mz,pxx1->bh);
                pxxq1->next=pxx1->next;
                Fwrite1(head1);
                return head1;
            }
            else
            {
                pxxq1=pxxq1->next;
                pxx1=pxxq1->next;

            }
        }
   
        getch();
    }
void Delxm(STU *head,char delxm[20]){          //删除图书
    STU *pxx,*pxxq;
    pxxq=head;
    pxx=pxxq->next;
    while(pxx!=NULL){
        if(strcmp(pxx->sbm,delxm)==0){//strcmp(char *str1,char *str2)
            printf("\t书本名\t作者\t价格\t图书编号\t书籍量\n");
            printf("\t%s\t%s\t%.2f\t%d\t\t%d\n",pxx->sbm,pxx->name,pxx->price,pxx->tsbh,pxx->sjl);
            pxxq->next=pxx->next;
            printf("删除成功!");
            Fwrite(head);
            return head;
        }
        else{
            pxxq=pxxq->next;
            pxx=pxxq->next;
        }
    }
    printf("删除失败!");
    Fwrite(head);
    return head;
}

//借阅
void Fwrite2(LENT *head2){          //保存  

    LENT *pxx;
    FILE *fp2;    //    定义一个文件指针
    fp2=fopen("lent.txt","wb");
    if(fp2==NULL){
        puts("文件打开失败!");
        return ;    }
    pxx=head2->next;
    while(pxx!=NULL){        
        fwrite(pxx,sizeof(LENT),1,fp2);
        pxx=pxx->next;
        }
   
    fclose(fp2);
    }
LENT *Fread2(){                        //读取文件
   
         LENT *head2,*end,*r;
         FILE *fp2;
         fp2=fopen("lent.txt","rb");
            if(fp2==NULL){
         puts("文件打开失败");
         return;    }
    head2=(LENT *)malloc(sizeof(LENT));
    end=head2;
    while(!feof(fp2)){    //若结束,返回非0,否则返回0
        r=(LENT *)malloc(sizeof(LENT));
        if(fread(r,sizeof(LENT),1,fp2)==1){
        end->next=r;
        end=r;
   
        }
    }
    end->next=NULL;
   
    fclose(fp2);
   
    return head2;
}
 
//图书
void Fwrite(STU *head){          //保存  

    STU *pxx;
    FILE *fp;    //    定义一个文件指针
    fp=fopen("stu.txt","wb");
    if(fp==NULL){
        puts("文件打开失败!");
        return ;    }
    pxx=head->next;
    while(pxx!=NULL){        
        fwrite(pxx,sizeof(STU),1,fp);
        pxx=pxx->next;
        }
   
    fclose(fp);
    }
STU *Fread(){                        //读取文件
   
         STU *head,*end,*r;
         FILE *fp;
         fp=fopen("stu.txt","rb");
            if(fp==NULL){
         puts("文件打开失败");
         return;    }
    head=(STU *)malloc(sizeof(STU));
    end=head;
    while(!feof(fp)){    //若结束,返回非0,否则返回0
        r=(STU *)malloc(sizeof(STU));
        if(fread(r,sizeof(STU),1,fp)==1){
        end->next=r;
        end=r;
   
        }
    }
    end->next=NULL;
   
    fclose(fp);
   
    return head;
}

//读者
void Fwrite1(DZ *head1){          //保存  
    int n=0;
    DZ *pxx;
    FILE *fp1;    //    定义一个文件指针
    fp1=fopen("dz.txt","wb");
    if(fp1==NULL){
        puts("文件打开失败!");
        return ;    }
    pxx=head1->next;
    while(pxx!=NULL){        
        fwrite(pxx,sizeof(DZ),1,fp1);
        pxx=pxx->next;
        n++;}
    fclose(fp1);
    }
DZ *Fread1(){                        //读取文件
    int n=0;
         DZ *head1,*end,*r;
         FILE *fp1;
         fp1=fopen("dz.txt","rb");
            if(fp1==NULL){
         puts("文件打开失败");
         return;    }
    head1=(DZ *)malloc(sizeof(DZ));
    end=head1;
    while(!feof(fp1)){    //若结束,返回非0,否则返回0
        r=(DZ *)malloc(sizeof(DZ));
        if(fread(r,sizeof(DZ),1,fp1)==1){
        end->next=r;
        end=r;
        n++;
        }
    }
    end->next=NULL;
    fclose(fp1);
   
    return head1;
} /*
//读取函数
STU *Fread()
{
    FILE *fp;
    STU *head,*p,*q;
    if((fp=fopen("g:\\软件\\图书馆\\图书馆答辩(1).txt","rb"))==NULL)
    {
        printf("不能读取文件");
        exit(0);
    }
    head=(STU *)malloc(sizeof(STU));
    fread(head,sizeof(STU),1,fp);
    if(head==NULL)
    {
        printf("文件打开错误");
        return NULL;
    }
    head->next=NULL;//1
    p=head;
    q=(STU *)malloc(sizeof(STU));
    fread(q,sizeof(STU),1,fp);
    while(!feof(fp))
    {
        q->next=NULL;
        p->next=q;
        p=q;
        q=(STU *)malloc(sizeof(STU));
        fread(q,sizeof(STU),1,fp);
    }
    printf("读取成功");


    system("cls");
    return head;
}
//保存函数
void Fwrite(STU *head)
{
    FILE *fp;
    STU *p;
    if((fp=fopen("g:\\软件\\图书馆\\图书馆答辩(1).txt","wb"))==NULL)
    {
        printf("不能建立文件");
        exit(0);
    }
    p=head;
    while(p!=NULL)
    {
        fwrite(p,sizeof(STU),1,fp);
        p=p->next;
    }
    fclose(fp);
   
    system("cls");
}
*/
void ADDxs(DZ *head1)         //添加学生
{
    DZ *pxxq1;
    DZ *pxx1;
    pxxq1=head1;
    pxx1=(DZ *)malloc(sizeof(DZ));
    C:{getchar();
    puts("请输入姓名:");
    gets(pxx1->mz);
    puts("请输入编号:");
    scanf("%d",&pxx1->bh);
    puts("请输入电话号码:");
    scanf("%d",&pxx1->dh);}
    while(pxxq1->next!=NULL)
    {
        pxxq1=pxxq1->next;
        if((strcmp(pxx1->mz,pxxq1->mz)==0)||(pxxq1->bh==pxx1->bh))
        {
            printf("输入有误!\n请重新输入!\n");
            goto C;
        }

    }
    pxxq1->next=pxx1;
    pxx1->next=NULL;
    printf("添加成功");
    Fwrite1(head1);
    return head1;
}
void Addxm(STU *head){          //增加图书
   
    STU *pxxq;
    STU *pxx;
   
    pxxq=head;
    pxx=(STU *)malloc(sizeof(STU));

   
    A:{getchar();
      puts("输入书本名:");
        gets(pxx->sbm);
        puts("输入作者:");
        gets(pxx->name);
        puts("请输入价格: ");
        scanf("%f",&pxx->price);
        getchar();
        puts("输入图书编号:");
        scanf("%d",&pxx->tsbh);
        puts("请输入书籍量: ");
        scanf("%d",&pxx->sjl);}
    while(pxxq->next!=NULL)
    {
        pxxq=pxxq->next;
        
        if(((strcmp(pxx->sbm,pxxq->sbm)==0)&&(strcmp(pxx->name,pxxq->name)==0))||(pxxq->tsbh==pxx->tsbh))
        {
            printf("输入有误!\n请重新输入!\n");
            goto A;}
    }
    pxxq->next=pxx;
    pxx->next=NULL;
    printf("添加成功\n");
    Fwrite(head);
   return head;
}
   


void cz(STU *head){//查找

    head=Fread();

    int select;
    char mc[30];//书本名称
    char zz[20];//作者
    STU *pxx;

    if(!head->next)
    {
        
        printf("\n这本书不存在!\n");
        getchar;
        return NULL;
    }

    printf("\n1.输入书本名查找\n2.输入作者名查找\n");
    printf("请选择 [1,2]:           ");
    scanf("%d",&select);
    getchar();
    switch(select)
    {
        case 1:
        printf("输入书本名:");
        gets(mc);
        pxx=head->next;
        if(strcmp(pxx->sbm,mc)!=0)
        {
            printf("未找到");
            break;
        }
        printf("\t书本名\t作者\t价格\t图书编号\t书籍量\n");
        while(pxx)
        {
            
            if(strcmp(pxx->sbm,mc)==0)
            {
            
                printf("\t%s\t%s\t%.2f\t%d\t\t%d\n",pxx->sbm,pxx->name,pxx->price,pxx->tsbh,pxx->sjl);
            }
            
            
               
            
            pxx=pxx->next;
        }
        getchar();
        break;
    case 2:
        printf("输入作者名:");
        gets(zz);
        pxx=head->next;
        printf("\t书本名\t作者\t价格\t图书编号\t书籍量\n");
        while(pxx)
        {
            if(strcmp(pxx->name,zz)==0)
            {
               
                printf("\t%s\t%s\t%.2f\t%d\t%d\n",pxx->sbm,pxx->name,pxx->price,pxx->tsbh,pxx->sjl);
            }
            pxx=pxx->next;
        }
        break;
    }
    return ;
}   




void Lend(STU *head,DZ *head1,LENT *head2)       //图书借阅
{
   
    head=Fread();
    head1=Fread1();
    head2=Fread2();
    LENT *q2,*p2;
    STU *p;
    DZ *p1;
    char dzmz[20];  //读者名字
    int jsbh,num=0;
    int n=0,m=0;
    p1=head1;
    getchar();
    puts("请输入读者的名字:");
    gets(dzmz);
    while(p1!=NULL)
    {
        if(strcmp(p1->mz,dzmz)==0)
        {
            printf("\t\t*****读者信息*****\n");
            printf("\n\t姓名\t读者身份证件号\t\t电话号码\n");
            printf("\n\t%s\t%d\t\t\t%d\n",p1->mz,p1->bh,p1->dh);
            n=1;
        }
        p1=p1->next;
    }
    if(n=0)
    {
        printf("此人还未注册\n请先注册或输入其他读者名字");
        return head2;
    }
    p=head;
    puts("请输入借阅图书的编号:");
    scanf("%d",&jsbh);
    while(p!=NULL)
    {
        if(p->tsbh==jsbh)
        {
        
            printf("\t\t*****图书信息*****\n");
            printf("\n\t书本名\t作者\t价格\t图书编号\t书籍量\n");
            printf("\t%s\t%s\t%.2f\t%d\t\t%d\n",p->sbm,p->name,p->price,p->tsbh,p->sjl);
            
        
        }
        p=p->next;
    }   

    q2=head2;
    p2=(LENT *)malloc(sizeof(LENT));
    strcpy(p2->lent_dz,p1->mz);
    p2->lent_dh=p1->dh;
    strcpy(p2->lent_name,p->name);
    strcpy(p2->lent_sbm,p->sbm);
    p2->lent_price=p->price;
    p2->lent_tsbh=p->tsbh;
    q2=q2->next;
   
    p2->next=NULL;
    Fwrite2(head2);            
    return head2;   
               
}

void Return(LENT *head2)
{
    LENT *p,*q;
    head2=Fread2();
    char hsxm[20];//还书姓名
    int hsbh; //还书编号
    q=head2;
    p=q->next;
    getchar();
    puts("请输入还书人姓名:");
    gets(hsxm);//还书姓名
    puts("请输入还书的图书编号:");
    scanf("%d",&hsbh);
    printf("\t\t*****读者借阅信息*****\n");
    printf("\n\t读者\t电话号码\t图书名称\t\t图书编号\t图书价格\t身份证号码\n");
    while(p)
    {
        if(strcmp(hsxm,p->lent_dz)==0&&p->lent_tsbh==hsbh)
        {
            printf("\t%s\t%d\t\t%s\t\t\t%d\t\t%.2f\t\t%d\n",p->lent_dz,p->lent_dh,p->lent_sbm,p->lent_tsbh,p->lent_price,p->lent_bh);
            q->next=p->next;
            printf("还书成功!");
            Fwrite2(head2);
            return head2;
        }
        p=p->next;
    }
   
    Fwrite2(head2);
    return head2;   
}

int menu(){                  //菜单
    int choose;
    puts("                                                ");
    puts("┏━━━━━━━━━━━━━━━━━━━━━━┓");
    puts("┃  Welcome to the result management system   ┃");
    puts("┃                  1-录入图书                ┃");
    puts("┃                  2-查看图书                ┃");
    puts("┃                  3-删除图书                ┃");
    puts("┃                  4-录入读者信息            ┃");
    puts("┃                  5-查看读者信息            ┃");
    puts("┃                  6-添加图书                ┃");
    puts("┃                  7-添加学生                ┃");
    puts("┃                  9-删除学生                ┃");
    puts("┃                  8-借阅                    ┃");
    puts("┃                  10-查看读者借阅情况       ┃");
    puts("┃                  13-还书                   ┃");
    puts("┃                  0-退出                    ┃");
    puts("┗━━━━━━━━━━━━━━━━━━━━━━┛");
    scanf("%d",&choose);
    return choose;
}

LENT *Kai()
{
    LENT *head2,*end2,*r2;
    int num;
    head2=(LENT *)malloc(sizeof(LENT));
    end2=head2;
    end2->next=NULL;
    while(1)
    {
        r2=(LENT *)malloc(sizeof(LENT));
        getchar();
        puts("请输入姓名:");
        gets(r2->lent_dz);
        puts("请输入电话号码:");
        scanf("%d",&r2->lent_dh);
        puts("请输入身份证件号:");
        scanf("%d",&r2->lent_bh);
        getchar();
        puts("请输入图书名称:");
        gets(r2->lent_sbm);
        puts("请输入图书编号:");
        scanf("%d",&r2->lent_tsbh);
        getchar();
        puts("请输入作者名字:");
        gets(r2->lent_name);
        puts("请输入图书价格:");
        scanf("%.2f",&r2->lent_price);
        end2->next=r2;
        end2=r2;
        getchar();
        printf("\n录入完成");
        printf("\n如果继续录入请按 1");
        printf("\n如果退出请按其他数字:");
        scanf("\n%d",&num);
        if(num!=1)
        {
            break;
        }
    }
   
    end2->next=NULL;
    Fwrite2(head2);
    return head2;
}
搜索更多相关主题的帖子: next STU head puts printf 
2017-12-17 22:37
我们0620
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-30
收藏
得分:0 
回复 2楼 自学的数学
谢谢   我可以看下   找找思路
2017-12-18 12:09
快速回复:借书模块 直接报错 求大佬帮忙
数据加载中...
 
   



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

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