#includestdio.h#includestring.h#includestdlib.h//支持system()函数#includeconio.h//支持getch()函数#includectype.h//支持isdigit()函数(判断是否为整形)#defineB_INFO_URLE:\\图书信息表.csv//结构体为图书信息typedefstructBook{intnumber;//图书编号charname[40];//图书名字charauth[20];//作者charpublish[50];//出版社structBook*next;}Book_info;//定义的机动变量,整个程序中的所有中间变量都存放在此结构体里边structtemp{charvalue[50];intmax_number;}T[3],max;/*主要函数介绍*/voidSetEnum();//显示导航页面voidJumpPage(intnumber);//控制主页面跳转函数intDeleteInfo();//删除图书信息函数intAddInfo();//添加图书信息函数intCheckInfo();//查看图书信息函数intUpdateInfo();//修改图书信息函数Book_info*ShowBookInfo();//读取文件信息存放在结构体中voidprint();//输出图书信息Book_info*ShowBookInfo(){FILE*fp=fopen(B_INFO_URL,r);if(fp==NULL){printf(文件打开失败!);exit(0);}fseek(fp,31,SEEK_SET);intn=0,v=0;Book_info*p,*q,*head;p=q=(structBook*)malloc(sizeof(structBook));while(feof(fp)==0){v++;fscanf(fp,%d,%s\n,&p-number,&p-name);char*result=NULL;result=strtok(p-name,,);//此方法是把一个字符串按规则分割成几部分intm=0;while(result!=NULL){strcpy(T[m].value,result);result=strtok(NULL,,);m++;}strcpy(p-name,T[0].value);strcpy(p-auth,T[1].value);strcpy(p-publish,T[2].value);if(v==1){head=p;}q-next=p;q=p;q-next=NULL;p=(structBook*)malloc(sizeof(structBook));}fclose(fp);returnhead;}voidprint(){printf(\n);FILE*fp=fopen(B_INFO_URL,r);if(fp==NULL){printf(\n\t文件打开失败!);exit(0);}charheader[30]=;fgets(header,sizeof(header),fp);char*result=NULL;result=strtok(header,,);//此方法是把一个字符串按规则分割成几部分while(result!=NULL){printf(%15s,result);result=strtok(NULL,,);}fclose(fp);printf(\n\n);Book_info*B;B=ShowBookInfo();//显示文件中的图书信息方法while(B!=NULL){if(B-name==NULL)break;printf(\t%-6d%-17s%-11s%-20s\n,B-number,B-name,B-auth,B-publish);if(B-numbermax.max_number){max.max_number=B-number;//保存最大的编号}B=B-next;}fclose(fp);printf(\n***********************************************************************);}//去掉data[0]charsetData(char*data){intnumber;for(number=1;number=30;number++){data[number-1]=data[number];}return*data;}//设置检索方式//以每个字符为匹配条件voidsetSearch(char*search,Book_info*bk,constcharor){while(bk!=NULL){intj=0,m=0;for(j;j30;j++){if(or=='a'){if(search[j]==bk-auth[j])m++;elsebreak;}elseif(or=='n'){if(search[j]==bk-name[j])m++;elsebreak;}}if(m=2){printf(\n\t%-6d%-17s%-11s%-20s\n,bk-number,bk-name,bk-auth,bk-publish);}bk=bk-next;}}intCheckInfo(){print();printf(\n\n\t提示:1、默认以图书名称为检索条件;\n\t2、首写字符为‘@’表示以作者为检索条件;\n\t3、首写字符为‘#’表示以图书编号为检索条件;);printf(\n\n***********************************************************************);printf(\n\n\t查看图书信息:);go:printf(\n\n\t按Enter继续,按Esc退出:);if(getch()==0x1b)return0;to:printf(\n\n\t请输入检索条件:);charsearch[30];scanf(%s,search);Book_info*bk;bk=ShowBookInfo();switch(search[0]){case'@':search[30]=setData(search);setSearch(search,bk,'a');break;case'#':intnumber;search[30]=setData(search);number=atoi(search);if(number==0){printf(\t输入不合法!);gototo;}while(bk!=NULL){if(bk-number==number)printf(\n\t%-6d%-17s%-11s%-20s\n,bk-number,bk-name,bk-auth,bk-publish);bk=bk-next;}break;default:setSearch(search,bk,'n');}gotogo;return0;}intUpdataInfo(){print();printf(\n\n\t修改图书信息:);Book_info*bk;bk=ShowBookInfo();while(1){printf(\n\n\t请根据提示数据数据(按Enter继续,按Esc退出):);if(getch()==0x1b)return0;go:printf(\n\n\t请输入图书编号:);chartemp[5];scanf(%s,&temp);intnumber=atoi(temp);if(number==0){printf(\t输入有误!);gotogo;}FILE*fp=fopen(B_INFO_URL,w+);constchar*header=图书编号,图书名称,作者,出版社\n;fputs(header,fp);fclose(fp);while(bk!=NULL){if(bk-number==number){printf(\n\t%-6d%-17s%-11s%-20s\n,bk-number,bk-name,bk-auth,bk-publish);printf(\n\n\t新图书名称:);scanf(%s,&bk-name);printf(\n\t新作者:);scanf(%s,&bk-auth);printf(\n\t新出版社:);scanf(%s,&bk-publish);}fp=fopen(B_INFO_URL,a+);fprintf(fp,%d,%s,%s,%s\n,bk-number,bk-name,bk-auth,bk-publish);fclose(fp);bk=bk-next;}}return0;}intAddInfo(){FILE*fp=fopen(B_INFO_URL,a+);if(fp==NULL){printf(\n\t文件打开失败!);return0;}charheader[30]=;fgets(header,sizeof(header),fp);if(header[0]==NULL){constchar*header=图书编号,图书名称,作者,出版社\n;fputs(header,fp);fclose(fp);printf(\n\t数据为空...\n\n********************************************************************);}else{print();}fclose(fp);printf(\n\n\t添加图书信息:\n\n\t请根据提示输入图书信息(按enter继续,按esc退出):);BookB_info;while(getch()!=0x1b){printf(\n\n\t图书名称:);scanf(%s,&B_info.name);printf(\t图书作者:);scanf(%s,&B_info.auth);printf(\t出版社:);scanf(%s,&B_info.publish);B_info.number=++max.max_number;fp=fopen(B_INFO_URL,a+);fprintf(fp,%d,%s,%s,%s\n,B_info.number,B_info.name,B_info.auth,B_info.publish);fclose(fp);printf(\n\tEnter继续,Esc退出?);}return0;}intDeleteInfo(){print();//打印出文件中的图书信息printf(\n\n\t删除图书信息:\n);go:printf(\n\t请输入图书编号(按Esc退出):);charn[4];intm=0;while((n[m]=getch())!=0x1b){//控制输入字符printf(%c,n[m]);if((int)n[m]48||(int)n[m]57){if((int)n[m]==13){if(m==0)gotogo;break;}printf(数据类型出错!);gotogo;}if(++m==5){printf(数据溢出!);gotogo;}}intnumber=atoi(n);//把字符串转换成数字if(number==0)return0;//如果为0认为是用户操作了esc键Book_info*bk,*prev;prev=bk=ShowBookInfo();//显示文件中的图书信息方法FILE*fp=fopen(B_INFO_URL,w+);constchar*header=图书编号,图书名称,作者,出版社\n;fputs(header,fp);fclose(fp);while(bk!=NULL){if(bk-number==number){prev-next=bk-next;}else{fp=f