您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 个人图书管理系统——c语言版
#include<stdio.h>#include<string.h>#include<stdlib.h>//Ö§³Ösystem()º¯Êý#include<conio.h>//Ö§³Ögetch()º¯Êý#include<ctype.h>//Ö§³Öisdigit()º¯Êý£¨ÅжÏÊÇ·ñΪÕûÐΣ©#defineB_INFO_URL"E:\\ͼÊéÐÅÏ¢±í.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->number>max.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;j<30;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(head
本文标题:个人图书管理系统——c语言版
链接地址:https://www.777doc.com/doc-4406911 .html