| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 999 人关注过本帖
标题:借书模块 直接报错 求大佬帮忙
只看楼主 加入收藏
我们0620
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-30
结帖率:0
收藏
 问题点数:0 回复次数:3 
借书模块 直接报错 求大佬帮忙
#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
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:0 
我倒是有一个这样的模块,你可以直接运行调试好了的,你要的话,我可以马上发给你。
2017-12-18 11:06
我们0620
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-30
收藏
得分:0 
回复 2楼 自学的数学
谢谢   我可以看下   找找思路
2017-12-18 12:09
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 2
#define PAGE 3
  /*图书结构体类型*/
  typedef struct
  {int num;        /*图书号*/
   char name[20];      /*书名*/
   char zuozhe[20];    /*作者姓名*/
   char chubanshe[20]; /*出版社*/
   int price;      /*价格*/
  }BOOKS;
int read_file(BOOKS books[])
     {  FILE *fp;
        int i=0;
        if((fp=fopen("project choose.txt","rt"))==NULL)
        { printf("\n\n*****库存文件不存在!请创建");
          return 0;
        }
        while(feof(fp)!=1)
        {  fread(&books[i],sizeof(BOOKS),1,fp);
           if(books[i].num==0)
              break;
           else
              i++;
        }
        fclose(fp);
        return i;
     }
 void save_file(BOOKS books[],int sum)
  {     FILE *fp;
      int i;
      if((fp=fopen("project choose.txt","wb"))==NULL)
      {   printf("读文件错误!\n");
          return;
      }
      for(i=0;i<sum;i++)
          if(fwrite(&books[i],sizeof(BOOKS),1,fp)!=1)
             printf("写文件错误!\n");
      fclose(fp);
 }

/*输入模块*/
 int input(BOOKS books[])
   {   int i=0;
       printf("\n\n                   录入图书信息   (最多%d种)\n",M);
       printf("----------------------------------------------------\n");
       do
       {   printf("\n                       第%d本图书",i+1);
       printf("\n                图书编号:");
           scanf("%d",&books[i].num);  if(books[i].num==0)  break;
       printf("\n                图书名称:");
           scanf("%s",books[i].name);
           printf("\n                作者:");
           scanf("%s",books[i].zuozhe);
           printf("\n                出版社:");
           scanf("%s",&books[i].chubanshe);
           printf("\n                图书价格:");
       scanf("%d",&books[i].price);
            i++;
       }while(i<M);
       printf("\n                  --%d种图书信息输入完毕!--\n",i);
       printf("\n                     按任意键返回主菜单!");
       getchar();
       return i;
   }

/*输出模块*/
    void output(BOOKS books[])
    {int i=0,j=0,page=1;
     printf("\n\n            --图书信息表--                 第%d页\n\n",page);
     printf("图书编号----图书名称-----作者----- 出版社-----图书价格\n");
     printf("-------------------------------------------------------\n");
     do
      {   if(books[i].num!=0)
      {   j++;
          if(j%PAGE!=0)
          { printf("%4d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
            printf("------------------------------------------------------\n");
          }
       else
          { printf("按任意键继续!");
            getchar();
            printf("\n\n     --图书信息表--                 第%d页\n\n",++page);
            printf("图书编号--图书名称--作者-- 出版社--图书价格\n");
            printf("------------------------------------------\n");
            printf("%4d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
            printf("---------------------------------------------\n");
           }
      }
        i++;
    }while(books[i].num!=0);
    printf("按任意键返回主菜单!");
    getchar( );
    }
/*给定编号,作者,出版社查找信息模块*/
     void find_by_num(BOOKS books[],int sum)     
    { int i,find_num;
      printf("\n               请输入要查找的图书编号:");
      scanf("%d",&find_num);
      for(i=0;i<sum;i++)
        if(books[i].num==find_num)      
        {
            printf("这是您所查找到的图书:\n");
            printf("图书编号----图书名称----作者---- 出版社---图书价格\n");
            printf("------------------------------------------\n");
            printf("%4d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                         books[i].zuozhe,  books[i].chubanshe,books[i].price);  
            printf("---------------------------------------------\n");
            break;
        }
          else
          {
            printf("\n       未找到要查找的图书信息,按任意键返回!");
            getchar();   
          }
    }

void find_by_zuozhe(BOOKS books[],int sum)
     {
      int i;
       char find_zuozhe[20];
       printf("\n               请输入要查找的作者姓名:");
       scanf("%s",find_zuozhe);
       for(i=0;i<sum-1;i++)
       if(strcmp(books[i].zuozhe,find_zuozhe)==0)
       {printf("这是您所查找到属于该作者的图书:");
        printf("图书编号--图书名称--作者-- 出版社--图书价格\n");
        printf("------------------------------------------\n");
        printf("%8d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
        printf("---------------------------------------------\n");
       }
       else
       {printf("\n       未找到要查找的图书信息,按任意键返回!");   
       }
     }

void find_by_chubanshe(BOOKS books[],int sum)
     {
      int i;
       char find_chubanshe[20];
       printf("\n               请输入要查找的出版社名称:");
       scanf("%s",find_chubanshe);
       for(i=0;i<sum;i++)
      if(strcmp(books[i].chubanshe,find_chubanshe)==0)
        {printf("这是您所查找到属于该出版社的图书:");
         printf("图书编号--图书名称--作者-- 出版社--图书价格\n");
         printf("------------------------------------------\n");
         printf("%8d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
         printf("---------------------------------------------\n");
        }
      else
       {printf("\n       未找到要查找的图书信息,按任意键返回!");
        getchar();
       }
     }
void find(BOOKS books[],int sum)
 { int choice;
      printf("\n     您要按照哪种方式查找?  \n");
      printf("\n      1.按图书编号查找  \n");
      printf("\n      2.按图书作者查找  \n");
      printf("\n      3.按出版社查找  \n");
      printf("\n      0. 退出\n");
      printf("\n       请选择(0-3):  \n");
      scanf("%d",&choice);
      switch(choice)  
      { case 1:     find_by_num(books,sum); break;
        case 2:     find_by_zuozhe(books,sum); break;
        case 3:     find_by_chubanshe(books,sum); break;
        case 0:                               break;
      }
     }  

/*删除信息模块*/
       void del(BOOKS books[])
     { int i,sum;
       int del_num;
      
             printf("\n               请输入要删除的图书编号:");
             scanf("%d",&del_num);
             for(i=0;i<sum;i++)
             if(books[i].num==del_num)
   
    {
             printf("这是您所要删除图书信息:\n");
             printf("图书编号----图书名称----作者---- 出版社----图书价格\n");
             printf("----------------------------------------------------\n");
             printf("%8d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
             printf("-----------------------------------------------------\n");                                
             printf("您确认要删除吗?");
             printf("按任意键继续!");
             getchar();
   
             printf("已成功删除图书信息!");
          }
     }

/*信息修改模块*/
     void modify(BOOKS books[],int sum)
     {int i=0,choice,modify_num,flag;
      do
      {
       printf("请输入要修改的图书编号:");
       scanf("%d",&modify_num);
       for(i=0;i<sum;i++)
       if(books[i].num==modify_num)
       { printf("\n\n            --图书信息--                 \n\n");
         printf("图书编号----图书名称----作者---- 出版社----图书价格\n");
        printf("------------------------------------------\n");
        printf("%8d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
        printf("---------------------------------------------\n");
         printf("\n                您要修改哪一项?\n");
         printf("\n                  1.图书名称\n");
         printf("\n                  2.作者\n");
         printf("\n                  3.出版社\n");
         printf("\n                  4.图书价格\n");
         printf("\n                 请选择(1-4):\n");
         scanf("%d",&choice);
         switch(choice)
         { case 1: printf("\n          请输入修改后的图书名称:");
               
                scanf("%s",books[i].name); break;   
           case 2: printf("\n          请输入修改后的作者姓名:");
                scanf("%s",books[i].zuozhe); break;   
           case 3: printf("\n          请输入修改后的出版社名称:");
                scanf("%s",books[i].chubanshe); break;   
           case 4: printf("\n          请输入修改后的图书价格:");
                scanf("%d",&books[i].price); break;   
         }
        printf("\n\n            --图书信息--                 \n\n");
         printf("图书编号----图书名称----作者---- 出版社----图书价格\n");
        printf("--------------------------------------------\n");
        printf("%8d %10s %10s %10s %8d \n",books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
        printf("---------------------------------------------\n");
        break;
       }
       else
       {printf("\n          该书不存在!");
        getchar();
       }
       printf("\n    修改成功!\n");
       printf("您要继续修改吗?(Y/N)");
       if (choice=='Y'||choice=='y')
       { flag=1;
         printf("\n                     继续!\n");
        }
       else flag=0;
      }while( flag==1);
   
       printf("\n     按任意键返回主菜单!");
       getchar();
      }

/*图书信息统计模块*/

void count(BOOKS books[],int sum)   /*统计某个出版社的图书数*/
      { int i;
       char count_chubanshe[20];
       int n=0;   
       printf("请输入一个出版社名称:\n");
       scanf("%s",count_chubanshe);     
       for(i=0;i<sum;i++)
       {         
         if( strcmp(books[i].chubanshe,count_chubanshe)==0)
             n++;
         break;
       }
       printf("统计出属于该出版社一共有%d本书\n",n);
     }

/*排序模块*/
     void sort(BOOKS books[],int sum)   /*按图书编号排序模块*/
     {BOOKS t;
      int i,j;
      printf("\n            --图书信息--      \n");
      printf("\n 排名 图书编号     图书名称        作者         出版社  图书价格\n");
       for(i=1;i<sum-1;i++)
        for(j=i+1;j<sum;j++)
           if(books[j].num>books[i].num)
           {t=books[j];
            books[j]=books[i];  
            books[i]=t;
           }
      for(i=0;i<sum;i++)
      { printf("%2d  %8d %12s %12s %12s %6d \n",i+1,books[i].num,books[i].name,
                 books[i].zuozhe,  books[i].chubanshe,books[i].price);
      }
     }

 main()
       { BOOKS books[M];
         int choice,sum;
         sum=read_file(books);
         if (sum==0)
         {printf("请录入基本图书信息!*******\n");
          sum=input(books);
         }
        do
       {
         printf("\n\n\n      *******图书馆理系统*******    \n\n");
         printf("                 1.修改图书信息 \n\n");
         printf("                 2.删除图书信息\n\n");
         printf("                 3.查找图书信息\n\n");
         printf("                 4.统计图书信息\n\n");
         printf("                 5.图书排行信息\n\n");
         printf("                 0.退出系统\n\n");
         printf("                  请选择\n\n");
         scanf("%d",&choice);
         switch(choice)
         {  case 1 :     modify(books,sum);    break;
            case 2 :     del(books);           break;
            case 3 :     find(books,sum);      break;
            case 4 :     count(books,sum);     break;
            case 5 :     sort(books,sum);      break;
            case 0 :                           break;
         }
       }while(choice!=0);
       save_file(books,sum);
}

2017-12-18 12:36
快速回复:借书模块 直接报错 求大佬帮忙
数据加载中...
 
   



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

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