图书管理系统,c语言完成

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
FILE *a,*b;
struct book syname(struct book *head);
struct book *paixu(struct book *head);
void tssr();//图书输入
void tsxg();/*图书修改*/
struct book *duqu3();/*读取图书*/
void yhsr();//用户输入
struct reader *tsgl();/*图书管理*/
struct reader *tslt();/*图书流通*/
struct reader *tscx();/*图书查询*/
int dzgl();/*读者管理*/
int yhgl();/*用户管理*/
void yhxg();/*用户修改*/
void yhxs();/*用户显示*/
struct link *yhsc();/*用户删除*/
struct link *dzsr(struct link *head);/*读者输入*/
struct link *dzxg(struct link *head);/*读者修改*/
struct link *dzcx();/*读者查询*/
struct link *dzsc();/*读者删除*/
struct link *dzxs();/*读者显示*/
void tsxianshi(struct book *head);//图书显示
int xuesheng();/*读者*/
void dzxxcr(struct link *head);
void dzxgmenu();/*读者修改的菜单*/
void dzglmenu();/*读者管理的菜单*/
void yhglmenu();/*用户管理菜单*/
void yhxxcr(struct link *head);/*用户信息存入*/
void menu();/*菜单*/
int book();/*图书管理员*/
int xitong();/*系统管理员*/
struct link *lianbiao(struct link *head,int n,char id[10],char password[10]);
struct link *lianbiao2(struct link *head,char id[10],char name[10],char xueyuan[10],long int phone,int kejie,int yijie);
struct book *lianbiao3(struct book *head,int record,int number,char name[10],char author[10],char publish[10],int have,int borrow);
int login(struct link *head);
struct link *duqu1(struct link *head);
struct link *duqu2(struct link *head);
struct link *xianshi(struct link *head);
struct link *xianshi2(struct link *head);
void xianshixtxg(struct link *head);/*账号的显示*/
struct link *zhuce(struct link *head);
struct link *xiugai();
struct suoyin// 索引
{
    char name[10];
    int i;
    int m;
    struct suoyin *next;
};
struct book
{
    int record;/*序号*/
    int number;/*书号*/
    char name[10];
    char author[10];
    char publish[10];
    int have;
    int borrow;
    struct book *next;
};
struct link
{
    char id[10];
    char password[10];
    int n;
    char name[10];
    char xueyuan [10];
    long int phone;
    int kejie;
    int yijie;
    struct link *next;
};
int main()
{
    struct link *head=NULL;
    int i;
    int j;
    printf("您好亲爱的用户\n");
    menu();
   while( scanf("%d",&i)!=EOF)
   {
    if(i==1)
    {
        head=duqu1(head);
        j=login(head);
            if(j==1)
            {
                printf("****************************************\n");
                printf("尊敬的学生您好\n");
                xuesheng();
            }
            if(j==2)
            {
                printf("****************************************\n");
                book();
                printf("尊敬的图书管理员您好\n");
            }
            if(j==3)
            {
                printf("****************************************\n");
                xitong();
                printf("尊敬的系统管理员你好\n");
            }
    }
    if(i==2)
    {
        head=zhuce(head);
        menu();
    }
    if(i==3)
    {
        return 0;
    }
   }
    return 0;
}
int login(struct link *head)
{
    struct link *pr=head,*p=NULL;
   char id[10],password[10],password2[10],password3[10];
   int w;
   printf("请输入您的账户:\n");
   scanf("%s",&id);
   printf("请输入您的密码:\n");
    scanf("%s",&password);
    if(pr==NULL)
    {
        printf("系统错误");
    }
    while(pr!=NULL)
    {
        if((strcmp(pr->id,id))!=0)
        {
            pr=pr->next;
        }
       if((strcmp(pr->id,id))==0)
        {
            if((strcmp(pr->password,password))==0)
            {
                w=pr->n;
                return w;
            }
            else
            {
                printf("很抱歉您输入的密码错误,请重试\n。");
                scanf("%s",&password2);
                if((strcmp(pr->password,password2))==0)
                {
                    w=pr->n;
                    return w;
                }
                else
                {
                    printf("很抱歉您输入的密码错误,请重试\n。");
                    scanf("%s",&password3);
                    if((strcmp(pr->password,password3))==0)
                    {
                        w=pr->n;
                        return w;
                    }
                    else
                    {
                        printf("很抱歉您输入的密码错误,请重试\n。");
                        w=4;
                        return 4;
                    }
                }
            }
        }
    }
    return w;
}
struct link *zhuce(struct link *head)
{
    struct link *p=NULL,*pr=head;
    p=(struct link *)malloc(sizeof(struct link));
    char id[10],password[10],password2[10];
    int n;
    printf("请输入您的用户名\n");
    scanf("%s",&id);
    printf("请输入您的密码\n");
    scanf("%s",&password);
    printf("请确认您的密码\n");
    scanf("%s",&password2);
    printf("如果您想注册为普通读者请输入1\n如果您想注册为图书管理员请输入2\n如果您想注册为系统管理员请输入3\n");
    scanf("%d",&n);
    if((strcmp(password,password2))==0)
    {
        printf("您的账号为%s\n密码为%s\n",id,password);
        strcpy(p->id,id);
        strcpy(p->password,password);
        p->n=n;
        if(p==NULL)
        {
        printf("无法注册该用户\n");
        return 0;
        }
    if(head==NULL)
    {
        head=p;
    }
    else
    {
        while(pr->next!=NULL)
        {
        pr=pr->next;
        }
        pr->next=p;
    }

           if ((a = fopen("注册.txt", "a")) == NULL)
                {
                printf("!!!!!!!!!!!!!!!!\n");
                exit(0);
                }
            else
                    {
                    while(pr!=NULL)
                    {
                        fprintf(a,"%s %s %d\n",pr->id,pr->password,pr->n);
                        pr=pr->next;
                    }
                    fclose(a);
                return head;
                }
    }
    else
    {
        printf("两次输入的密码错误\n");
        return 0;
    }
    return 0;
}
struct link *xianshi(struct link *head)/*读取登录函数通用*/
{
    struct link *p=head;
    while(p!=NULL)
    {
        printf("%s ",p->id);
        if(p->n==1)
        {
            printf("读者\n");
        }
        if(p->n==2)
        {
            printf("图书管理\n");
        }
        if(p->n==3)
        {
            printf("系统管理员\n");
        }
        p=p->next;
    }
}
struct link *duqu1(struct link *head)/*读取函数*/
{
    struct link *pr=head,*p=NULL;
    int n,kejie,yijie;
    char id[10],password[10],name[10],xueyuan[10];
    long int phone;
    if((a=fopen("C:\\Users\\86182\\Desktop\\秃头生涯\\寒假实验\\c语言终极实验\\注册.txt","r"))==NULL)
    {
    printf("无法注册该账号,系统错误");
    return 0;
    }
    else
    {
        while(!feof(a))
        {
            p=(struct link *)malloc(sizeof(struct link));
            if(p==NULL)
            {
            printf("end");
            return 0;
            }
            fscanf(a,"%s %s %d\n",&id,&password,&n);
            head=lianbiao(head,n,id,password);
        }
        fclose(a);
    }
    return head;
}
void menu()/*菜单*/
{
    printf("****************************************\n");
    printf("1.登录账号\n2.注册账号\n3.退出软件\n");
    printf("****************************************\n");
}
struct link *lianbiao(struct link *head,int n,char id[10],char password[10])/*登录链表*/
{
        struct link *p=NULL,*pr=head;
        p=(struct link *)malloc(sizeof(struct link));
        if(p==NULL)
        {
            printf("系统错误");
            return 0;
        }
        if(head==NULL)
        {
            head=p;
        }
        else
        {
            while(pr->next!=NULL)
            {
                pr=pr->next;
            }
            pr->next=p;
        }
        strcpy(p->id,id);
        strcpy(p->password,password);
        p->n=n;
        p->next=NULL;
        return head;
}
int xuesheng()/*读者*/
{
    struct link *head;
    int i;
    printf("尊敬的同学您好。\n");
    printf("1.密码修改\n2.图书查询系统\n3.退出程序\n");
    while(scanf("%d",&i)!=EOF)
    {
        if(i==1)
        {
           head=xiugai();
        }
        if(i==2)
        {
            tscx();
        }
        if(i==3)
        {
            return 0;
        }
    }
}
int book ()/*图书管理员*/
{
    struct link *head;
    int i;
    printf("尊敬的老师您好。\n");
    printf("1.修改密码\n2.读者管理子系统\n3.图书管理子系统\n4.图书流通管理子系统\n");
    while(scanf("%d",&i)!=EOF)
    {
        if(i==1)
        {
            head=xiugai();
        }
        if(i==2)
        {
            printf("您将进入读者管理界面\n");
            dzgl();
        }
        if(i==3)
        {
            printf("图书管理\n");
            tsgl();
        }
        if(i==4)
        {
            printf("图书流通\n");
            tslt();
        }
    }


}
int xitong()/*系统管理员*/
{
     struct link *head;
    int i;
    printf("尊敬的系统管理员您好。\n");
    printf("您可以使用\n1.读者管理系统\n2.修改密码\n");
    while(scanf("%d",&i)!=EOF)
    {
        if(i==1)
        {
            yhgl();
        }
        if(i==2)
        {
            head=xiugai();
        }

    }
}
struct link *xiugai()/*修改密码函数*/
{
    char id[10];
    char password[10],password2[10];
    struct link *head=NULL;
    head=duqu1(head);
    struct link *pr=head;
    printf("请输入那您的用户名\n");
    scanf("%s",&id);
    printf("请输入您想修改的密码\n");
    scanf("%s",&password);
    printf("请再次确认您的密码\n");
    scanf("%s",&password2);
    if((strcmp(password,password2))!=0)
    {
        printf("两次输入的密码不同\n");
        return 0;
    }
    if((strcmp(password,password2))==0)
    {
        while(pr!=NULL)
        {
            printf("执行\n");
            if((strcmp(pr->id,id))!=0)
            {
                pr=pr->next;
            }
            if((strcmp(pr->id,id))==0)
            {
                strcpy (pr->password,password);
                if ((a = fopen("注册.txt", "w")) == NULL)
                {
                printf("!!!!!!!!!!!!!!!!\n");
                exit(0);
                }
                else
                {
                    while(pr!=NULL)
                    {
                        fprintf(a,"%s\n%s\n%d\n",pr->id,pr->password,pr->n);
                        pr=pr->next;
                    }
                    fclose(a);
                return head;
                }
            }
        }
    }
    return head;
}
int  dzgl()/*读者管理*/
{
    struct link *head=NULL;
    int i;
    dzglmenu();
    while(scanf("%d",&i)!=EOF)
    {
        if(i==1)
        {
           head=dzsr(head);
        }
        if(i==2)
        {
            head=dzxg(head);/*读者修改*/
        }
        if(i==3)
        {
            head=dzsc();
        }
        if(i==4)
        {
           head=dzxs();
        }
        if(i==5)
        {
            head=dzcx();
        }
        if(i==6)
        {
            return 0;
        }
       dzglmenu();
    }
    return 0;
}
struct reader *tsgl()/*图书管理*/
{
    struct book *head;
    int i;
    printf("欢迎来到图书管理界面\n");
    printf("请输入您想要执行的选项\n1.图书信息输入\n2.图书信息修改\n3.图书信息查询\n4.汇总统计\n5.返回主菜单\n");
    scanf("%d",&i);
    if(i==1)
    {
        tssr();
    }
    if(i==2)
    {
        tsxg();
    }
    if(i==3)
    {
        head=duqu3(head);
        head=paixu(head);
        tsxianshi(head);
        syname(head);
    }
    if(i==4)
    {

    }
    if(i==5)
    {

    }
}
struct reader *tslt()/*图书流通*/
{

}
struct link *dzsr(struct link *head)/*读者输入*/
{
    head=NULL;
        struct link *pr=head,*p=NULL;
        char id[10];
        char name[10];
        char xueyuan[10];
        long int phone;
        int kejie;
        int yijie;
        head=duqu1(head);
        xianshi(head);
        pr=head;
        printf("请输入您想输入信息的账号");
        scanf("%s",&id);
        while(pr!=NULL)
        {
        if((strcmp(pr->id,id))!=0)
        {
            pr=pr->next;
        }
        if((strcmp(pr->id,id))==0)
        {
        printf("****************************************\n");
        printf("请输入该学生的个人基本信息\n1.该学生的姓名\n2.该学生的学院\n3.该学生的手机号\n4.该学生的借阅图书数量\n5.该学生已经借阅图书的数量\n");
        printf("****************************************\n");
        scanf("%s %s %ld %d %d",&name,&xueyuan,&phone,&kejie,&yijie);
        strcpy(pr->name,name);
        strcpy(pr->xueyuan,xueyuan);
        pr->phone=phone;
        pr->kejie=kejie;
        pr->yijie=yijie;
        if((b=fopen("读者信息.txt","a"))==NULL)
        {
            printf("系统错误\n");
            return 0;
        }
            else
            {
            printf("执行\n");
            fprintf(a,"%s %s %s %ld %d %d\n",pr->id,pr->name,pr->xueyuan,pr->phone,pr->kejie,pr->yijie);
            pr=pr->next;
            }
                    fclose(b);
                    return head;
            }
        }
}
struct link *dzxg(struct link *head)/*读者修改*/
{
    char id[10],name[10],xueyuan[10];
    long int phone;
    int kejie,yijie,i;
    head=duqu2(head);
    xianshi2(head);
    struct link *pr=head;
    printf("请输入您想要修改的用户名。\n");
    scanf("%s",&id);
    while(pr!=NULL)
    {
        if((strcmp(pr->id,id))!=0)
        {
            pr=pr->next;
        }
        if((strcmp(pr->id,id))==0)
        {

            while(scanf("%d",&i)!=EOF)
            {
                dzxgmenu();
                if(i==1)
                {
                    printf("请输入读者姓名\n");
                    scanf("%s",&name);
                    strcpy(pr->name,name);
                    printf("%s",pr->name);
                }
                if(i==2)
                {
                    printf("请输入读者的学院\n");
                    scanf("%s",&xueyuan);
                    strcpy(pr->xueyuan,xueyuan);
                }
                if(i==3)
                {
                    printf("请输入该学生的联系方式\n");
                    scanf("%ld",&phone);
                    pr->phone=phone;
                }
                if(i==4)
                {
                    printf("请输入该学生可借阅的图书的数量\n");
                    scanf("%d",&kejie);
                    pr->kejie=kejie;
                }
                if(i==5)
                {
                   printf("请输入该学生已经借阅图书的数量\n");
                   scanf("%d",&yijie);
                   pr->yijie=yijie;
                }
                if(i==6)
                {
                    if ((a = fopen("读者信息.txt", "w")) == NULL)
                    {
                        printf("!!!!!!!!!!!!!!!!\n");
                        exit(0);
                    }
                    else
                    {
                        while(head!=NULL)
                        {
                            fprintf(a,"%s %s %s %ld %d %d\n",head->id,head->name,head->xueyuan,head->phone,head->kejie,head->yijie);
                            head=head->next;
                        }
                        fclose(a);
                        return 0;
                    }
                }
            }
        }
    }
}
struct link *dzcx()/*读者查询*/
{
    struct link *head=NULL;
    struct link *pra=NULL;
    pra=(struct link *)malloc(sizeof(struct link));
    char id[10],name[10],xueyuan[10];
    long int phone;
    int kejie,yijie;
    head=duqu2(head);
    xianshi2(head);
    struct link *pr=head;
    struct link *p=head;
    printf("请输入您想要搜索的用户名.\n");
    scanf("%s",&id);
    if(head==NULL){
        printf("该系统还没有输入具体的用户信息.\n");
    }
    while((strcmp(id,p->id))!=0&&p->next!=NULL)
    {
        pr=p;
        p=p->next;
    }
    if((strcmp(id,p->id))==0)
    {
        strcpy(name,p->name);
        strcpy(xueyuan,p->xueyuan);
        phone=p->phone;
        kejie=p->kejie;
        yijie=p->yijie;
         if(p==head)
        {
            head=p->next;
        }
        else
            {
                pr->next=p->next;
            }
        free(p);
        pra->next=head;
        head=pra;
        strcpy(pra->id,id);
        strcpy(pra->name,name);
        strcpy(pra->xueyuan,xueyuan);
       pra->phone=phone;
       pra->kejie=kejie;
       pra->yijie=yijie;
        xianshi2(head);
    }
}
struct link *dzsc()/*读者删除*/
{
    struct link *head=NULL;
    char id[10];
    head=duqu2(head);
    xianshi2(head);
    struct link *p=head;
    struct link *pr=head;
    printf("请输入您想要删除的用户名\n");
    scanf("%s",&id);
    if(head==NULL)
    {
        printf("this link is empty\n");
    }
    while((strcmp(id,p->id))!=0&&p->next!=NULL)
    {
       pr=p;
       p=p->next;
    }
    if((strcmp(p->id,id))==0)
    {
        printf("%s\n",p->id);
        if(p==head)
        {
            head=p->next;
        }
        else
            {
                pr->next=p->next;
            }
        free(p);
    }
    else
        {
            printf("没有找到该用户名\n");
        }
        xianshi2(head);
       dzxxcr(head);
    return head;

}
struct link *dzxs()/*读者显示*/
{
    struct link *head=NULL;
    head=duqu2(head);
    xianshi2(head);

}
void dzglmenu()
{
    printf("****************************************\n");
    printf("您将有以下权力\n1.读者输入\n2.读者修改\n3.读者删除\n4.读者显示\n5.读者查询\n6返回主界面\n");
    printf("****************************************\n");
}
struct link *duqu2(struct link *head)
{
     struct link *pr=head,*p=NULL;
    int n,kejie,yijie;
    char id[10],password[10],name[10],xueyuan[10];
    long int phone;
    if((a=fopen("C:\\Users\\86182\\Desktop\\秃头生涯\\寒假实验\\c语言终极实验\\读者信息.txt","r"))==NULL)
    {
    printf("无法注册该账号,系统错误");
    return 0;
    }
    else
    {
        while(!feof(a))
        {
            p=(struct link *)malloc(sizeof(struct link));
            if(p==NULL)
            {
            printf("end");
            return 0;
            }
            fscanf(a,"%s %s %s %ld %d %d\n",&id,&name,&xueyuan,&phone,&kejie,&yijie);
            head=lianbiao2(head,id,name,xueyuan,phone,kejie,yijie);
        }
    }
    return head;
}
struct link *lianbiao2(struct link *head,char id[10],char name[10],char xueyuan[10],long int phone,int kejie,int yijie)
{
    struct link *p=NULL,*pr=head;
        p=(struct link *)malloc(sizeof(struct link));
        if(p==NULL)
        {
            printf("系统错误\n");
            return 0;
        }
        if(head==NULL)
        {
            head=p;
        }
        else
        {
            while(pr->next!=NULL)
            {
                pr=pr->next;
            }
            pr->next=p;
        }
        strcpy(p->id,id);
        strcpy(p->name,name);
        strcpy(p->xueyuan,xueyuan);
        p->phone=phone;
        p->kejie=kejie;
        p->yijie=yijie;
        p->next=NULL;
        return head;

}
struct link *xianshi2(struct link *head)
{
     struct link *p=head;
    while(p!=NULL)
    {
        printf("%s %s %s %ld %d %d\n",p->id,p->name,p->xueyuan,p->phone,p->kejie,p->yijie);
        p=p->next;
    }
}
void dzxgmenu()//读者管理菜单
{
            printf("****************************************\n");
            printf("请输入您想修改的选项\n");
            printf("1.读者姓名\n2.读者学院\n3.读者联系方式\n4.读者可借阅图书数量\n5.读者已经借阅图书的数量\n6.结束该程序\n");
            printf("****************************************\n");
}
int yhgl()/*用户管理*/
{
    int i;
    yhglmenu();
    while(scanf("%d",&i)!=EOF)
    {
        if(i==1)
        {
            printf("欢迎进入用户输入系统\n");
            yhsr();
        }
        if(i==2)
        {
            printf("欢迎来到用户信息修改系统\n");
            yhxg();
        }
        if(i==3)
        {
            printf("欢迎来到用户删除系统\n");
            yhsc();
        }
        if(i==4)
        {
            printf("用户信息显示\n");
            yhxs();
        }
        if(i==5)
        {
            printf("用户密码修改\n");
            xiugai();
        }
        if(i==6)
        {
           exit (0);
        }
        yhglmenu();
    }

}
void yhglmenu()/*用户管理菜单*/
{

    printf("1. 用户信息输入\n2. 用户信息修改\n3. 用户信息删除\n4. 用户信息显示\n5. 用户密码修改\n6. 返回主菜单\n");
}
void yhsr()/*用户输入*/
{
    char id[10];
    char password[10],password2[10];
    int n;
    struct link *head=NULL;
    head=duqu1(head);
    printf("请输入您想要输入的账号\n");
    scanf("%s",&id);
    printf("请输入您想要输入账号的密码\n");
    scanf("%s",&password);
    printf("请再次输入您想要输入的密码\n");
    scanf("%s",&password2);
    if((strcmp(password,password2))!=0)
    {
        printf("两次输入的密码不一样\n");
        exit(0);
    }
    if((strcmp(password,password2))==0)
    {
        printf("您的账号为%s\n给您的账户密码为\n");
        printf("该账户的身份为\n1.读者\n2.读者管理\n3.系统管理员\n");
        scanf("%d",&n);
        if((a=fopen("注册.txt","a"))==NULL)
        {
            printf("注册失败\n");
            exit(0);
        }
        else
            {
                fprintf(a,"%s\n%s\n%d\n",id,password,n);
                fclose(a);
            }
    }
}
void yhxg()/*用户修改*/
{
    char id[10],password[10],id2[10];
    int n,i;
    struct link *head=NULL;
    printf("执行\n");
    head=duqu1(head);
    xianshixtxg(head);
    struct link *pr=head;
   printf("请输入您想修改账号的账号名\n");
   scanf("%s",&id);
   while(head!=NULL)
   {
       if((strcmp(head->id,id))!=0)
          {
              head=head->next;
          }
          if((strcmp(head->id,id))==0)
            {
                printf("请输入您想要修改的项目\n1.用户名\n2.用户密码\n3.用户的身份\n4.结束进程\n");
                while(scanf("%d",&i)!=EOF)
                {
                    if(i==1)
                    {
                        printf("请输入您想要修改的用户名\n");
                        scanf("%s",&id2);
                        strcpy(head->id,id2);
                    }
                    if(i==2)
                    {
                        printf("请输入您想要修改的密码\n");
                        scanf("%s",&password);
                        strcpy(head->password,password);
                    }
                    if(i==3)
                    {
                        printf("请输入您想要修改的用户身份的号\n1.读者\n2.读者管理\n3.系统管理\n");
                        scanf("%s",&n);
                        head->n=n;
                    }
                     if ((a = fopen("注册.txt", "w")) == NULL)
                    {
                        printf("!!!!!!!!!!!!!!!!\n");
                        exit(0);
                    }
                        else
                        {
                            while(pr!=NULL)
                            {
                                fprintf(a,"%s %s %d\n",pr->id,pr->password,pr->n);
                                pr=pr->next;
                            }
                                fclose(a);
                    if(i==4)
                    {
                        exit (0);
                    }
                        head=duqu1(head);
                        xianshixtxg(head);
                        printf("请输入您想要修改的项目\n1.用户名\n2.用户密码\n3.用户的身份\n4.结束进程\n");
                    }
                }

            }
        }
}
void yhxs()/*用户显示*/
{
    struct link *head=NULL;
    head=duqu1(head);
    xianshi(head);
}
void xianshixtxg(struct link *head)
{
    struct link *p=head;
    while(p!=NULL)
    {
        printf("%s %s ",p->id,p->password);
        if(p->n==1)
        {
            printf("读者\n");
        }
        if(p->n==2)
        {
            printf("图书管理\n");
        }
        if(p->n==3)
        {
            printf("系统管理员\n");
        }
        p=p->next;
    }
}
void dzxxcr(struct link *head)/*读者显示存入*/
{
    struct link *pr=head;
     if ((a = fopen("读者信息.txt", "w")) == NULL)
                {
                printf("!!!!!!!!!!!!!!!!\n");
                exit(0);
                }
            else
                    {
                    while(pr!=NULL)
                    {
                        fprintf(a,"%s %s %s %ld %d %d\n",pr->id,pr->name,pr->xueyuan,pr->phone,pr->kejie,pr->yijie);
                        pr=pr->next;
                    }
                    fclose(a);
                    }
}

struct link *yhsc()/*用户删除*/
{
    struct link *head=NULL;
    char id[10];
    head=duqu1(head);
    xianshi(head);
    struct link *p=head;
    struct link *pr=head;
    printf("请输入您想要删除的用户名\n");
    scanf("%s",&id);
    if(head==NULL)
    {
        printf("该系统错误\n");
        exit (0);
    }
    while((strcmp(p->id,id))!=0&&p->next!=NULL)
    {
        pr=p;
        p=p->next;
    }
    if((strcmp(p->id,id))==0)
    {
        printf("%s\n",p->id);
        if(p==head)
        {
            head=p->next;
            printf("执行\n");
        }
        else{
            printf("执行2\n");
            pr->next=p->next;
        }
        free(p);
    }
    else
        {
        printf("没有找到该用户\n");
        }
    xianshi(head);
    yhxxcr(head);

}
void yhxxcr(struct link *head)/*用户信息存入*/
{
      struct link *pr=head;
     if ((a = fopen("注册.txt", "w")) == NULL)
                {
                printf("!!!!!!!!!!!!!!!!\n");
                exit(0);
                }
            else
                    {
                    while(pr!=NULL)
                    {
                        fprintf(a,"%s %s %d\n",pr->id,pr->password,pr->n);
                        pr=pr->next;
                    }
                    fclose(a);
                    }
}
void tssr()/*图书输入*/
{
    int record,number,have,borrow,n;
    char name[10],author[10],publish[10];
    struct book *head=NULL;
    struct book *pr=head,*p=NULL;
    head=duqu3(head);
    while(head->next!=NULL)
    {
        n=head->record+1;
        head=head->next;
    }
    p=(struct book *)malloc(sizeof(struct book));
    printf("请输入该本书的书号。\n");
    scanf("%d",&number);
    printf("请输入该本书的书名。\n");
     scanf("%s",&name);
     printf("请输入该本书的作者。\n");
     scanf("%s",&author);
    printf("请输入该本书的出版社。\n");
    scanf("%s",&publish);
     printf("请输入该本书的藏数量。\n");
     scanf("%d",&have);
     printf("请输入该本书的借出量。\n");
     scanf("%d",&borrow);

     if((a=fopen("图书信息.txt","a"))==0)
     {
         printf("图书信息丢失\n");
     }
     else
        {
            fprintf(a,"%d %d %s %s %s %d %d\n",n,number,name,author,publish,have,borrow);
            fclose(a);
        }

}
struct book *duqu3()/*读取图书*/
{
    struct book *head=NULL,*p=NULL;
    int record,number,have,borrow;
    char name[10],author[10],publish[10];
    if((a = fopen("图书信息.txt", "r"))==NULL)    /*if ((a = fopen("注册.txt", "a")) == NULL)*/
    {
        printf("无法输入图书信息,系统错误\n");
            return 0;
    }
    else
        {

        while(!feof(a))
        {
            p=(struct book *)malloc(sizeof(struct book));
            if(p==NULL)
            {
                printf("end\n");
                return 0;
            }
            fscanf(a,"%d %d %s %s %s %d %d\n",&record,&number,&name,&author,&publish,&have,&borrow);
             head=lianbiao3(head,record,number,name,author,publish,have,borrow);
        }
        fclose(a);
        }
        return head;
}
struct book *lianbiao3(struct book *head,int record,int number,char name[10],char author[10],char publish[10],int have,int borrow)
{
    struct book *p=NULL,*pr=head;
    p=(struct book *)malloc(sizeof(struct link));
        if(p==NULL)
        {
            printf("系统错误\n");
            return 0;
        }
        if(head==NULL)
        {
            head=p;
            p->record=record;
            strcpy(p->name,name);
            strcpy(p->author,author);
            strcpy(p->publish,publish);
            p->number=number;
            p->have=have;
            p->borrow=borrow;
        }
        else
        {
                while(pr->next!=NULL)
                      {
                          pr=pr->next;
                      }
                      pr->next=p;
                       p->record=record;
                   strcpy(p->name,name);
                   strcpy(p->author,author);
                   strcpy(p->publish,publish);
                   p->number=number;
                   p->have=have;
                   p->borrow=borrow;
        }
                   return head;
}
void tsxianshi(struct book *head)/*图书信息显示*/
{
    struct book *pr=head;
    while(pr!=NULL)
    {
        printf("%d %d %s %s %s %d %d\n",pr->record,pr->number,pr->name,pr->author,pr->publish,pr->have,pr->borrow);
        pr=pr->next;
    }
}
void tsxg()/*图书修改*/
{
    char name[10],author[10],publish[10];
    int have,borrow,number,record,i;
    struct book *head=NULL;
    head=duqu3(head);
    printf("zhixing\n");
    tsxianshi(head);
    struct book *pr=head;
    printf("请输入您想要修改的书号\n");
    scanf("%d",&number);
    while(head!=NULL)
    {
        if(number!=head->number)
        {
            head=head->next;
        }
        if(number==head->number)
        {
            printf("请输入您想要修改的数据\n1.书号\n2.书名\n3.作者\n4.出版社\n5.拥有数量\n6.借出数量\n7.退出当前界面\n");
            while(scanf("%d",&i)!=EOF)
            {
                if(i==1)
                {
                 printf("请输入您想要修改的书号\n");
                 scanf("%d",&number);
                 head->number=number;
                }
                if(i==2)
                {
                    printf("请输入您想要修改的书名\n");
                    scanf("%s",&name);
                    strcpy(head->name,name);
                }
                 if(i==3)
                {
                    printf("请输入您想要修改的作者\n");
                    scanf("%s",&author);
                    strcpy(head->author,author);
                }
                 if(i==4)
                {
                    printf("请输入您想要修改的出版社\n");
                    scanf("%s",&publish);
                    strcpy(head->publish,publish);
                }
                 if(i==5)
                {
                    printf("请输入您想要修改的拥有图书的数量\n");
                     scanf("%d",&have);
                    head->have=have;
                }
                if(i==6)
                {
                    printf("请输入您想要修改的借出量\n");
                    scanf("%d",&borrow);
                    head->borrow=borrow;
                }
                if((a=fopen("图书信息.txt","w"))==NULL)
                {
                    printf("该文件为空\n");
                }
                else
                    {
                        while(pr!=NULL)
                        {
                            fprintf(a,"%d %d %s %s %s %d %d\n",pr->record,pr->number,pr->name,pr->author,pr->publish,pr->have,pr->borrow);
                            pr=pr->next;
                        }
                        fclose(a);
                    }
                     if(i==7)
                    {
                    exit(0);
                    }
                    head=duqu3(head);
                    tsxianshi(head);
                     printf("请输入您想要修改的数据\n1.书号\n2.书名\n3.作者\n4.出版社\n5.拥有数量\n6.借出数量\n7.退出当前界面\n");
                     if(head==NULL)
                    {
                        printf("该书号不存在\n");
                        exit (0);
                    }
            }
        }
    }
}
struct book *paixu(struct book *head)//按书名排序
{
 struct book *p,*pr=head,other;
 if(head==NULL)
 {
     printf("该链表为空链表\n");
     exit(0);
 }
 if(head->next==NULL)
 {
     printf("该链表只有一个节点不需要经行排序\n");
     exit(0);
 }
 else
    {
        while(pr->next!=NULL)
           {
               p=pr->next;
               while(p!=NULL)
               {

                   if(strcmp(pr->name,p->name)>0)
                   {
                       other=*pr;
                       *pr=*p;
                       *p=other;
                       other.next=pr->next;
                       pr->next=p->next;
                       p->next=other.next;
                   }
                   p=p->next;
               }
               pr=pr->next;
           }
           return head;
    }
}
struct book syname(struct book *head)//图书名字索引
{
    printf("\n\n\n\n");
    struct book *pr=head,*p=NULL;
    struct suoyin *shead=NULL,*sp=NULL;
    struct suoyin *spr=shead;
    p=pr->next;
    int i=1,m;
    char name[10];
    while(pr->next!=NULL)
    {
        while(p!=NULL)
        {
            sp=(struct suoyin *)malloc(sizeof (struct suoyin));
            if((strcmp(pr->name,p->name))==0)
            {

                if(p->next==NULL)
                {
                    i=i+1;
                    strcpy(name,pr->name);
                    m=p->record;
                    pr=p;
                    p=pr->next;
                    break;
                }
                 i=i+1;
                p=p->next;
            }
            if((strcmp(pr->name,p->name))!=0)
            {
                strcpy(name,pr->name);
                m=pr->record;
                pr=p;
                p=pr->next;
                break;
            }
        }
        printf("%s %d %d\n",name,i,m);
        i=1;
    }
}
struct reader *tscx()
{
    struct book *head=NULL;
    struct book *pra=NULL;
    pra=(struct book *)malloc(sizeof(struct link));
    char name[10],author[10],publish[10];
    int record,number,have,borrow;
     head=duqu3(head);
     head=paixu(head);
    tsxianshi(head);
    syname(head);
    printf("请输入您想要查询的书名\n");
    scanf("%s",&name);
    struct book *pr=head;
    struct book *p=head;
    if(head==NULL)
    {
        printf("该系统并未输入关于书的信息\n");
    }
    while((strcmp(name,p->name))!=0&&p->next!=NULL)
    {
    pr=p;
    p=p->next;
    }
    if((strcmp(name,p->name))==0)
    {
        strcpy(author,p->author);
        strcpy(publish,p->publish);
        record=p->record;
        have=p->have;
        borrow=p->borrow;
        number=p->number;
    if(p==head)
    {
        head=p->next;
    }
    else
    {
        pr->next=p->next;
    }
    free(p);
    pra->next=head;
    head=pra;
    strcpy(pra->author,author);
    strcpy(pra->name,name);
    strcpy(pra->publish,publish);
    pra->have=have;
    pra->borrow=borrow;
    pra->record=record;
    pra->number=number;
    tsxianshi(head);

    }
}
 

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值