资源描述:
《图书管理系统_c语言[1]》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、图书管理系统_c语言[1]#include#include#include#include#defineSTACK_INIT_SIZE10#defineOK1#defineTRUE1#defineFALSE0#defineERROR0structstudent/*定义学生类型,用于存放借出的书籍*/{intcarnum;charlendbook[10];}student[1000];structemploy/*定义职工类型*/{intemploynum;charemployname[15];intemplo
2、yage;charemploysex[2];charemployleve[10];longintemploytage;}employ[50];structbook/*定义书的类型*/{intbooknum;charbookname[10];charbookcreat[10];intturefalse;/*用于借书和还书模块判断一本书是否借出的条件*/}book[1000];structcar/*借书卡的数据类型*/{intcarnum;charstudentname[10];intstudentclass;}car[100];huanbook()/*还书函数*/{FILE*fp,*
3、fp2;/*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/inti,n;intcarnum;charlendbook[10];printf("请你输入你的卡号");scanf("%d",&carnum);fp=fopen("car.txt","r");/*读取卡号记录*/for(i=0;fread(&car[i],sizeof(structcar),1,fp)!=0;i++)/*for循环判断卡号是否存在*/{if(car[i].carnum==carnum)/*卡号存在,进入下一循环*/{n=i;fclose(fp);printf("请输入你要还的书
4、的名字");scanf("%s",lendbook);fp=fopen("record.txt","r");for(i=0;fread(&student[i],sizeof(structstudent),1,fp)!=0;i++)/*判断是否借阅了输入的书*/{if(strcmp(student[i].lendbook,lendbook)==0)/*借阅了该书,进入下一循环,否则出错显示*/{fclose(fp);fp=fopen("record.txt","r");fp2=fopen("bookl.txt","w");for(i=0;fread(&student[i],siz
5、eof(structstudent),1,fp)!=0;i++){if(strcmp(student[i].lendbook,lendbook)==0){continue;/*删除还掉的书的借书记录*/}fwrite(&student[i],sizeof(structstudent),1,fp2);/*写入原来没还的书的记录*/}fclose(fp);fclose(fp2);fp=fopen("record.txt","w");fp2=fopen("bookl.txt","r");for(i=0;fread(&student[i],sizeof(structstudent),1,f
6、p2)!=0;i++){fwrite(&student[i],sizeof(structstudent),1,fp);/*将借书记录信息写回*/}fclose(fp);fclose(fp2);fopen("bookl.txt","w");/*清临时文件的记录*/fclose(fp2);fp=fopen("book.txt","r");fp2=fopen("bookl.txt","w");for(i=0;fread(&book[i],sizeof(structbook),1,fp)!=0;i++)/*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/{if(i==n){boo
7、k[i].turefalse=1;fwrite(&book[i],sizeof(structbook),1,fp2);/*将还的书的原来状态设为无人借阅的*/continue;}fwrite(&book[i],sizeof(structbook),1,fp2);}fclose(fp);fclose(fp2);fp=fopen("book.txt","w");fp2=fopen("bookl.txt","r");for(i=0;fread(&book[i],sizeof