#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <direct.h>
#include <conio.h>
struct borrow
{
char q_name[22], name[22];//书名,借阅者名字
}b;
char w[1010][222];//删除借阅信息
char w1[1010][222];//删除图书信息
struct book_information
{
char number[22], name[22], author[22], from[22], time[22], price[22];
}book, w2[1010];//图书信息修改
char w3[1010][222];//验证用户通过
struct node
{
char name[22], pwd[22], re_pwd[22], sex[22];
char age[22];
char phone[22];
}s;
void main1();
int recog_pwd(char name[22], char pwd[22]);//验证管理员账号
int save();//用户注册保持数据
int recog_pwd2(char name[22], char pwd[22]);//验证用户账号
void LOGIN(int a);//登录界面
void user();//用户功能界面
void admin();//管理员功能界面
void a_book_input();//图书信息录入
void a_book_look();//图书信息浏览
void a_book_search();//图书信息查询
void a_book_delete();//图书信息删除
void a_book_change();//图书信息更改
void a_text();//验证用户注册
int a_text1(char name1[]);//用户注册通过//把 ¥用户注册提交。txt¥ 转化成 ¥用户。txt¥
void u_search();//借阅者查询
void u_borrow();//借阅者借阅
void u_save();//借阅书保存记录
int u_status(char name1[]);
void u_return();
int u_r(char name1[]);
int main()//主程序
{
system("color fc");
main1();
return 0;
}
void main1()
{
printf("\n\n");
printf(" 登录界面\n\n");
printf(" 1: 管理员登录\n");
printf(" 2: 借阅者登录\n\n");
printf(" Please Enter Choose: ");
int a;
scanf("%d", &a);
printf("\n");
system("cls");//清屏
printf("\n");
LOGIN(a);//登录界面
}
int recog_pwd(char name[22], char pwd[22])//验证管理员账号
{
FILE *fp;
char str[22];
if((fp=fopen("管理员.txt", "r"))==NULL)
{
printf("用户不存在\n");
return 0;
}
fscanf(fp, "%s", str);
if(strcmp(str, name)==0)
{
fscanf(fp, "%s", str);
if(strcmp(str, pwd)==0)
{
return 1;
}
else
{
return 0;
}
}
return 0;
}
int save()//用户注册保存数据
{
FILE*fp;
fp=fopen("用户注册提交.txt", "at+");
fprintf(fp,"%s ", s.name);
fprintf(fp, "%s ", s.pwd);
fprintf(fp, "%s ", s.re_pwd);
fprintf(fp, "%s ", s.age);
fprintf(fp, "%s ", s.sex);
fprintf(fp, "%s\n", s.phone);
fclose(fp);
return 1;
}
int recog_pwd2(char name[22], char pwd[22])//验证用户账号
{
FILE *fp;
char str[222], name1[22], pwd1[22];
if((fp=fopen("用户.txt", "r"))==NULL)
{
printf("用户不存在\n");
return 0;
}
while(!feof(fp))
{
fscanf(fp, "%s", name1);
strcpy(b.name, name1);//全局
fscanf(fp, "%s", pwd1);
if(strcmp(name, name1)==0&&strcmp(pwd, pwd1)==0)
{
return 1;
}
fgets(str, 222, fp);
}
fclose(fp);
return 0;
}
void LOGIN(int a)//登录界面(包括管理员与借阅者)
{
int i;
if(a==1)//管理员登录
{
char name[22], pwd[22];
printf("\n 用户名: ");
scanf("%s", name);
getchar();
printf("\n");
printf(" 密码: ");
scanf("%s", pwd);
getchar();
printf("\n");
printf("正在登录,请稍后\n");
for(i=0; i<10; i++)
{
printf("...");
Sleep(60);
}
if(recog_pwd(name, pwd)==1)
{
printf("登录成功!\n");
}
else
{
printf("登录失败!返回上一级\n");
LOGIN(1);
system("cls");
}
system("cls");
admin();
}
if(a==2)//借阅者登录
{
printf("\t\t1: 新用户注册\n");
printf("\t\t2: 直接登录\n\n");
int b;
printf("Please Enter Choose: ");
scanf("%d", &b);
system("cls");//清屏
printf("\n");
if(b==1)//新用户注册
{
int flag=1;
while(flag==1)//判断是否注册成功
{
printf("\t\t用户名:");
scanf("%s", s.name);
printf("\n");
printf("\t\t密码:");
scanf("%s", s.pwd);
printf("\n");
char re_pwd[22];
int flag1=1;
while(flag1==1)//判断确定密码
{
printf("\t\t确认密码:");
scanf("%s", re_pwd);
if(strcmp(re_pwd, s.pwd)==0)
{
strcpy(s.re_pwd, re_pwd);
flag1=0;
}
else
{
printf("前后密码不一致,请重新输入\n");
}
}
printf("\n");
printf("\t\t年龄:");
scanf("%s", s.age);
printf("\n");
printf("\t\t性别:");
scanf("%s", s.sex);
printf("\n");
printf("\t\t联系方式:");
scanf("%s", s.phone);
printf("\n");
if(save()==1)
{
printf("\t注册提交成功!请耐心等待\n");
flag=0;
}
else
{
printf("\t注册提交失败!\n请重新注册:\n");
}
printf("\n\n");
printf("\t\t按任意键继续:");
getch();
system("cls");
main1();
}
}
if(b==2)//直接登录
{
char name[22], pwd[22], re_pwd[22];
int flag1=1;
while(flag1==1)
{
printf("\t\t用户名:");
scanf("%s", name);
printf("\n");
printf("\t\t密码:");
scanf("%s", pwd);
printf("\n");
int flag=1;
while(flag==1)
{
printf("\t\t确认密码:");
scanf("%s", re_pwd);
if(strcmp(re_pwd, pwd)==0)
{
flag=0;
}
else
{
printf("请重新确定密码:\n");
}
}
printf("\n");
if(recog_pwd2(name, pwd)==1)
{
printf("\t\t登录成功!\n");
flag1=0;
}
else
{
printf("\t\t登录失败!\n请重新登录\n");
Sleep(1000);
system("cls");
}
}
system("cls");
user();
}
system("cls");//清屏
}
}
void admin()//管理员功能界面
{
system("cls");
printf(" 图书管理系统\n\n");
printf(" ************************************************* \n");
printf(" | 1---------图书信息录入---------- |\n");
printf(" | 2-----图书信息浏览-------------- |\n");
printf(" | 3-图书信息查询------------------ |\n");
printf(" | 4------------图书信息删除------- |\n");
printf(" | 5--------图书信息修改----------- |\n");
printf(" | 6-----借阅者注册验证------------ |\n");
printf(" | 0-------------------退出-------- |\n");
printf(" | |\n");
printf(" *************************************************\n\n");
printf("Please Enter Choose: ");
int c;
scanf("%d", &c);
system("cls");
switch(c)
{
case 1: a_book_input(); break;
case 2: a_book_look();
printf("\n请输入任意键返回上一层: ");
getch();
system("cls");
admin();
break;
case 3: a_book_search(); break;
case 4: a_book_delete(); break;
case 5: a_book_change(); break;
case 6: a_text();break;
case 0: break;
}
}
void a_book_input()//图书信息录入
{
int flag=1;
while(flag==1)
{
system("cls");
printf("\t\t\t\t 图书信息录入\n\n");
printf("\t\t\t请输入书籍的书号:");
scanf("%s", book.number);
printf("\t\t\t请输入书名:");
scanf("%s", book.name);
printf("\t\t\t请输入作者名:");
scanf("%s", book.author);
printf("\t\t\t请输入出版社:");
scanf("%s", book.from);
printf("\t\t\t请输入出版时间:");
scanf("%s", book.time);
printf("\t\t\t请输入该书的价格:");
scanf("%s", book.price);
FILE*fp;
fp=fopen("图书.txt", "at");
fprintf(fp, "%s ", book.number);
fprintf(fp, "%s ", book.name);
fprintf(fp, "%s ", book.author);
fprintf(fp, "%s ", book.from);
fprintf(fp, "%s ", book.time);
fprintf(fp, "%s\n", book.price);
fclose(fp);
printf("\n");
printf("\t是否继续录入图书:\n\n");
printf("\t1, 继续\n");
printf("\t2, 退出\n\n");
int d;
printf("\t请输入:");
scanf("%d", &d);
if(d==2)
{
flag=0;
}
}
system("cls");
admin();//再次运行功能菜单
}
void a_book_look()//图书信息浏览
{
printf("\t 全部图书信息\n\n");
FILE*fp;
char str[222];
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
printf("\n");
printf("\t书号 书名 作者 出版社\t出版时间\t价格\t\n\n");
while(fgets(str, 222, fp)!=NULL)
{
if(strlen(str)!=1)//会出现文件末尾读空行的现象
printf("\t%s\n", str);
}
fclose(fp);
return;
}
void a_book_search()//图书查询
{
int flag1=1;
while(flag1==1)
{
system("cls");
printf("\n\t请确定查询方式:\n\n");
printf("\t1, 按书名查询\n");
printf("\t2, 按作者查询\n\n");
int a;
printf("请输入:");
scanf("%d", &a);
if(a==1)//书名查询
{
int flag=1;
while(flag==1)
{
system("cls");
printf("\n\t请输入书名:");
char name1[22];
scanf("%s", name1);
FILE*fp;
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
char str[222], number[22], name[22], auther[22], from[22], time[22], price[22];
while(!feof(fp))
{
fscanf(fp, "%s", number);
fscanf(fp, "%s", name);
fscanf(fp, "%s", auther);
fscanf(fp, "%s", from);
fscanf(fp, "%s", time);
fscanf(fp, "%s", price);
if(strcmp(name1, name)==0)
{
flag=0;
printf("查询结果:\n\n");
printf("书号:%s \n书名:%s \n作者:%s \n出版社:%s \n出版时间:%s \n价格:%s \n", number, name, auther, from, time, price);
printf("\n");
break;
}
fgets(str, 222, fp);
}
fclose(fp);
if(flag==1)
{
printf("\t未查询到结果!\n");
printf("\t请确定是否继续查询\n\n");
printf("\t1: 继续查询\n");
printf("\t2: 退出\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
system("cls");
admin();
}
}
}
}
if(a==2)//作者查询
{
int flag=1;
while(flag==1)
{
system("cls");
printf("\n\t请输入作者:");
char name1[22];
scanf("%s", name1);
FILE*fp;
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
char str[222], number[22], name[22], auther[22], from[22], time[22], price[22];
while(!feof(fp))
{
fscanf(fp, "%s", number);
fscanf(fp, "%s", name);
fscanf(fp, "%s", auther);
fscanf(fp, "%s", from);
fscanf(fp, "%s", time);
fscanf(fp, "%s", price);
if(strcmp(name1, auther)==0)
{
flag=0;
printf("查询结果:\n\n");
printf("书号:%s \n书名:%s \n作者:%s \n出版社:%s \n出版时间:%s \n价格:%s \n", number, name, auther, from, time, price);
printf("\n");
break;
}
fgets(str, 222, fp);
}
fclose(fp);
if(flag==1)
{
printf("\t未查询到结果!\n\n");
printf("\t请确定是否继续查询\n\n");
printf("\t1: 继续查询\n");
printf("\t2: 退出\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
system("cls");
admin();
}
}
}
}
printf("\t请确定是否继续查询\n\n");
printf("\t1: 继续查询\n");
printf("\t2: 退回上一层\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
flag1=0;
}
}
system("cls");
admin();
return;
}
void a_book_delete()//图书信息删除
{
int flag=1;
while(flag==1)
{
system("cls");
a_book_look();
printf("\n请输入删除书籍的书号:");
char number1[22];
scanf("%s", number1);
FILE *fp;
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("图书文件打开失败");
return;
}
int i, n, q;
char str[222], number2[22];
i = 0;
while(!feof(fp))
{
i++;
fscanf(fp, "%s", number2);
fgets(str, 222, fp);
if(strcmp(number2, number1)==0)
{
q = i;
break;
}
}
fclose(fp);
FILE*fp1;
if((fp1=fopen("图书.txt", "r"))==NULL)
{
printf("图书文件打开失败");
return;
}
i = 0;
while(!feof(fp1))//txt到w1[i]
{
i++;
fgets(w1[i], 222, fp1);
}
n = i;
fclose(fp1);
for(i=q; i<=n; i++)
{
strcpy(w1[i], w1[i+1]);
}
FILE*fp2;
fp2 = fopen("图书.txt", "w");
for(i=1; i<=n-1; i++)
{
fprintf(fp2, "%s", w1[i]);
}
fclose(fp2);
printf("\n\t删除成功!");
printf("\t请确定是否继续删除:\n\n");
printf("\t 1, 继续删除\n");
printf("\t 2, 退回上一级\n");
printf("请输入: ");
int a;
scanf("%d", &a);
if(a==2)
{
flag=0;
system("cls");
admin();
return;
}
}
return;
}
void a_book_change()//图书信息修改
{
int flag=1;
while(flag==1)
{
system("cls");
a_book_look();
printf("\t请输入任意键进入下一步:");
getch();
system("cls");
int i=0, n, q=-1;
int flag1=1;
while(flag1==1)
{
system("cls");
printf("\n\t请输入需要修改书籍的书名:");
char name1[22];
scanf("%s", name1);
FILE*fp;
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
char str0[222], number[22], name[22], auther[22], from[22], time[22], price[22];//查询该书籍信息
i = 0;
while(!feof(fp))
{
i++;
fscanf(fp, "%s", number);
fscanf(fp, "%s", name);
fscanf(fp, "%s", auther);
fscanf(fp, "%s", from);
fscanf(fp, "%s", time);
fscanf(fp, "%s", price);
fgets(str0, 222, fp);
if(strcmp(name1, name)==0)
{
flag1=0;
q = i;//找到第几行
printf("查询结果:\n\n");
printf("书号:%s \n书名:%s \n作者:%s \n出版社:%s \n出版时间:%s \n价格:%s \n", number, name, auther, from, time, price);
printf("\n");
break;
}
}
fclose(fp);
if(flag1==1)
{
printf("\t\t未查询到此书,");
printf("\t请重新输入书名, 按任意键继续\n");
getch();
}
}
i=0;
char str1[222];
FILE*fp1;
if((fp1=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
while(!feof(fp1))//txt到w2[i]
{
i++;
fscanf(fp1, "%s", w2[i].number);
fscanf(fp1, "%s", w2[i].name);
fscanf(fp1, "%s", w2[i].author);
fscanf(fp1, "%s", w2[i].from);
fscanf(fp1, "%s", w2[i].time);
fscanf(fp1, "%s", w2[i].price);
fgets(str1, 222, fp1);
}
n = i;
fclose(fp1);
printf("\t请输入修改的方面: \n");
printf("\t1:书号\n");
printf("\t2:书名\n");
printf("\t3:作者\n");
printf("\t4:出版社\n");
printf("\t5:出版时间\n");
printf("\t6:价格\n");
printf("\n");
printf("请输入: ");
int a;
scanf("%d", &a);
printf("\n");
switch(a)
{
case 1: printf("\n请输入新的书号:");
scanf("%s", w2[q].number);break;
case 2: printf("\n请输入新的书名:");
scanf("%s", w2[q].name);break;
case 3: printf("\n请输入新的作者:");
scanf("%s", w2[q].author);break;
case 4: printf("\n请输入新的出版社:");
scanf("%s", w2[q].from);break;
case 5: printf("\n请输入新的出版时间:");
scanf("%s", w2[q].time);break;
case 6: printf("\n请输入新的价格:");
scanf("%s", w2[q].price);break;
}
FILE*fp2;
fp2=fopen("图书.txt", "w");
for(i=1; i<=n; i++)
{
printf("%s %s %s %s %s %s\n", w2[i].number, w2[i].name, w2[i].author, w2[i].from, w2[i].time, w2[i].price);
}
for(i=1; i<=n; i++)
{
fprintf(fp2, "%s ", w2[i].number);
fprintf(fp2, "%s ", w2[i].name);
fprintf(fp2, "%s ", w2[i].author);
fprintf(fp2, "%s ", w2[i].from);
fprintf(fp2, "%s ", w2[i].time);
fprintf(fp2, "%s\n", w2[i].price);
}
fclose(fp2);
printf("\n\t修改完成\n");
printf("\t请确定是否继续修改\n\n");
printf("\t1: 继续修改\n");
printf("\t2: 退回上一层\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
flag=0;
}
}
system("cls");
admin();
}
void a_text()//验证注册
{
int flag=1;
int sum;
while(flag==1)
{
system("cls");
sum=0;
printf("\n\t\t用户注册提交:\n\n");
FILE*fp;
fp=fopen("用户注册提交.txt", "at+");
char str[222];
while(fgets(str, 222, fp)!=NULL)
{
if(strlen(str)!=1)
{
printf("%s\n", str);
sum++;
}
}
printf("\n");
if(sum>0)
{
printf("请确定可以通过验证的用户名: ");
char name1[22];
scanf("%s", name1);
printf("\n\n");
if(a_text1(name1)==1)
{
printf("确定成功!\n");
}
else
{
printf("确定失败!\n");
}
printf("\n\n");
printf("确定是否继续:\n\n");
printf("1, 继续\n");
printf("2, 退出\n\n");
int a;
scanf("%d", &a);
if(a==1)
{
flag=1;
}
if(a==2)
{
break;
}
}
else
{
printf("\t已无人注册\n\n");
printf("\t按任意键继续\n");
getch();
break;
}
}
system("cls");
admin();
}
int a_text1(char name1[])//把 ¥用户注册提交。txt¥ 转化成 ¥用户。txt¥再把原用户注册提交的删除
{
FILE*fp;
fp=fopen("用户注册提交.txt", "r");
if(fp==NULL)
{
printf("用户注册提价文件未打开");
return 0;
}
char str[222], name2[22];
int i, q, n;
i = 0;
while(!feof(fp))
{
i++;
fscanf(fp, "%s", name2);
fgets(str, 222, fp);
if(strcmp(name1, name2)==0)
{
q = i;
break;
}
}
rewind(fp);
i=0;
while(!feof(fp))
{
i++;
fgets(w3[i], 222, fp);
}
n = i;
fclose(fp);
FILE*fp1;
fp1 = fopen("用户.txt", "at+");
fprintf(fp1, "%s", w3[q]);
fclose(fp1);
for(i=q; i<=n; i++)
{
strcpy(w3[i], w3[i+1]);
}
FILE*fp2;
fp2 = fopen("用户注册提交.txt", "w");
for(i=1; i<=n-1; i++)
{
fprintf(fp2, "%s", w3[i]);
}
fclose(fp2);
return 1;
}
void user()//借阅者功能界面
{
system("cls");
printf(" 图书借阅系统\n\n");
printf(" ************************************************* \n");
printf(" | 1-------------------查阅图书 |\n");
printf(" | 2-------------------借阅图书 |\n");
printf(" | 3-------------------图书归还 |\n");
printf(" | 0-------------------退出 |\n");
printf(" | |\n");
printf(" *************************************************\n\n");
printf("Please Enter Choose: ");
int a;
scanf("%d", &a);
switch(a)
{
case 1: u_search();break;
case 2: u_borrow();break;
case 3: u_return();break;
case 0: break;
}
return;
}
void u_search()//借阅者查询
{
int flag1=1;
while(flag1==1)
{
system("cls");
printf("\n\t请确定查询方式:\n\n");
printf("\t1, 按书名查询\n");
printf("\t2, 按作者查询\n\n");
int a;
printf("请输入:");
scanf("%d", &a);
if(a==1)//书名查询
{
int flag=1;
while(flag==1)
{
system("cls");
printf("\n\t请输入书名:");
char name1[22];
scanf("%s", name1);
FILE*fp;
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
char str[222], number[22], name[22], auther[22], from[22], time[22], price[22];
while(!feof(fp))
{
fscanf(fp, "%s", number);
fscanf(fp, "%s", name);
fscanf(fp, "%s", auther);
fscanf(fp, "%s", from);
fscanf(fp, "%s", time);
fscanf(fp, "%s", price);
if(strcmp(name1, name)==0)
{
flag=0;
printf("查询结果:\n\n");
printf("书号:%s \n书名:%s \n作者:%s \n出版社:%s \n出版时间:%s \n价格:%s \n", number, name, auther, from, time, price);
printf("\n");
break;
}
fgets(str, 222, fp);
}
fclose(fp);
if(flag==1)
{
printf("\t未查询到结果!\n");
printf("\t请确定是否继续查询\n\n");
printf("\t1: 继续查询\n");
printf("\t2: 退出\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
system("cls");
user();
}
}
}
}
if(a==2)//作者查询
{
int flag=1;
while(flag==1)
{
system("cls");
printf("\n\t请输入作者:");
char name1[22];
scanf("%s", name1);
FILE*fp;
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
char str[222], number[22], name[22], auther[22], from[22], time[22], price[22];
while(!feof(fp))
{
fscanf(fp, "%s", number);
fscanf(fp, "%s", name);
fscanf(fp, "%s", auther);
fscanf(fp, "%s", from);
fscanf(fp, "%s", time);
fscanf(fp, "%s", price);
if(strcmp(name1, auther)==0)
{
flag=0;
printf("查询结果:\n\n");
printf("书号:%s \n书名:%s \n作者:%s \n出版社:%s \n出版时间:%s \n价格:%s \n", number, name, auther, from, time, price);
printf("\n");
break;
}
fgets(str, 222, fp);
}
fclose(fp);
if(flag==1)
{
printf("\t未查询到结果!\n\n");
printf("\t请确定是否继续查询\n\n");
printf("\t1: 继续查询\n");
printf("\t2: 退出\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
system("cls");
user();
}
}
}
}
printf("\t请确定是否继续查询\n\n");
printf("\t1: 继续查询\n");
printf("\t2: 退回上一层\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
flag1=0;
}
}
system("cls");
user();
return;
}
void u_borrow()//借阅者借阅
{
int flag1=1;
while(flag1==1)
{
system("cls");
printf("\n\t请输入书名:");
char name1[22];
scanf("%s", name1);
FILE*fp;
if((fp=fopen("图书.txt", "r"))==NULL)
{
printf("文件未打开");
return;
}
char str[222], number[22], name[22], auther[22], from[22], time[22], price[22];
while(!feof(fp))
{
fscanf(fp, "%s", number);
fscanf(fp, "%s", name);
fscanf(fp, "%s", auther);
fscanf(fp, "%s", from);
fscanf(fp, "%s", time);
fscanf(fp, "%s", price);
strcpy(b.q_name, name);
if(strcmp(name1, name)==0)
{
printf("查询结果:\n\n");
printf("书号:%s \n书名:%s \n作者:%s \n出版社:%s \n出版时间:%s \n价格:%s \n", number, name, auther, from, time, price);
printf("\n");
break;
}
fgets(str, 222, fp);
}
fclose(fp);
printf("\t借阅状态:\n");
if(u_status(name)==1)
{
printf("\t\t\t已被他人借阅, 请借阅其他书籍\n");
}
else
{
printf("\t\t\t可借阅\n\n");
printf("请确定是否要借阅此书:\n\n");//每本书只有一本
printf("1, 是,我确定\n");
printf("2, 否,返回上一级\n\n");
int a;
printf("请输入: ");
scanf("%d", &a);
printf("\n");
system("cls");
if(a==1)
{
printf("\n借阅成功!\n\n");//借阅次数限制
u_save();
}
}
printf("\t请确定是否继续借阅\n\n");
printf("\t1: 继续借阅\n");
printf("\t2: 退回上一层\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
flag1=0;
}
}
system("cls");
user();
}
void u_save()//借阅者借阅之借阅书籍信息保存
{
FILE*fp;
fp=fopen("借阅书籍信息.txt", "at");
fprintf(fp, "%s ", b.q_name);
fprintf(fp, "%s\n", b.name);
fclose(fp);
}
int u_status(char name1[])//借阅状态
{
FILE*fp;
fp = fopen("借阅书籍信息.txt", "at+");
char str[222], name[22];
while(!feof(fp))
{
fscanf(fp, "%s", name);
fgets(str, 222, fp);
if(strcmp(name, name1)==0)
{
return 1;
}
}
fclose(fp);
return 0;
}
void u_return()//归还图书
{
int flag=1;
while(flag==1)
{
system("cls");
printf("\n\n\t\t请输入归还书籍的名字: ");
char name[22];
scanf("%s", name);
printf("\n\n请诚实地输入您借书持续时间: ");
int time;
scanf("%d", &time);
printf("\n\n");
if(u_r(name)==1)
{
printf("归还成功!");
}
if(time>30)
{
printf("亲爱的用户, 您借书逾期 %d 天\n", time-30);
printf("\t\t您需要缴费 %.1f 元, 谢谢支持\n", (double)(time-30)*0.1);
}
printf("\t请确定是否继续归还\n\n");
printf("\t1: 继续归还\n");
printf("\t2: 退回上一层\n");
printf("请输入: ");
int b;
scanf("%d", &b);
if(b==2)
{
flag=0;
}
}
system("cls");
user();
}
int u_r(char name1[])//归还图书之删除借阅信息
{
FILE*fp;
fp = fopen("借阅书籍信息.txt", "r");
if(fp==NULL)
{
printf("借阅书籍信息文件不存在\n");
return 0;//??????????????????????????????????
}
int i, n, q;
i = 0;
char name2[22], str[222];
while(!feof(fp))
{
i++;
fscanf(fp, "%s", name2);
fgets(str, 222, fp);
if(strcmp(name1, name2)==0)
{
q = i;
break;
}
}
fclose(fp);
FILE*fp1;
if((fp1=fopen("借阅书籍信息.txt", "r"))==NULL)
{
printf("借阅书籍信息文件打开失败");
return 0;
}
i = 0;
while(!feof(fp1))//txt到w[i]
{
i++;
fgets(w[i], 222, fp1);
}
n = i;
fclose(fp1);
for(i=q; i<=n; i++)
{
strcpy(w[i], w[i+1]);
}
FILE*fp2;
fp2 = fopen("借阅书籍信息.txt", "w");
for(i=1; i<=n-1; i++)
{
fprintf(fp2, "%s", w[i]);
}
fclose(fp2);
return 0;
}
课堂设计之图书馆借书系统
最新推荐文章于 2023-06-09 21:28:00 发布