fclose(fp);
fclose(fp2);
fopen("bookl.txt","w");
fclose(fp2);
printf("借书完毕,按任意键返回\n");
getch();
return;
}
}
printf("不存在这样的书,任意键返回\n");
fclose(fp);
getch();
return;
}
}
printf("你的卡号不存在,请申请新卡,按任意键返回\n");
fclose(fp);
getch();
}
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d张卡<卡号:%d 姓名:%s 班级:%d>\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
getch();
}
delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的卡号\n");
printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%d",&carnum);
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(&car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("car.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp2)!=0;i++)
{
fwrite(&car[i],sizeof(struct car),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("请你输入卡号\n");
scanf("%d",&car[i].carnum);
printf("请你输入学生姓名\n");
scanf("%s",car[i].studentname);
printf("请你输入班级\n");
scanf("%d",&car[i].studentclass);
fwrite(&car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("输入完毕,任意键返回\n");
getch();
}
changemploy()
{
FILE *fp,*fp2;
char employname[10],choice;
int i;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的职工的书字\n");
scanf("%s",employname);
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employ[i].employname,employname)==0)
{
printf("你所要修改的职工的资料如下,请选择你要修改的内容\n");
printf("<职工号:%d职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d>\n",employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
printf("1:修改职工的号\n");
printf("2:修改职工名\n");
printf("3:修改职工年龄\n");
printf("4:修改职工工资\n");
printf("5:修改职工学历\n");
printf("请输入1-5:");
scanf("%s",&choice);
switch(choice)
{
case '1':
{
printf("请输入新的职工号\n");
scanf("%d",&employ[i].employnum);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '2':
{
printf("请输入新的职工姓名\n");
scanf("%s",employ[i].employname);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '3':
{
printf("请输入新的年龄\n");
scanf("%d",&employ[i].employage);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '4':
{
printf("请输入新的职工工资\n");
scanf("%d",&employ[i].employtage);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '5':
{
printf("请输入新的职工学历\n");
scanf("%s",employ[i].employleve);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}
defaut:printf("没有这样的操作");break;
}
continue;
}
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(&employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}
delemploy()
{
FILE *fp,*fp2;
int i;
char employname[10],choice;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的职工名\n");
printf("如果你输入的职工存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",employname);
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employname,employ[i].employname)!=0)
{
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该职工信息?删除后的所有信息将无法恢复《Y/N》\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(&employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
employcount()
{
FILE *fp;
int i,n=0;
fp=fopen("employ.txt","r");
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
printf("第%d职工的信息如下:\n<职工号:%d 职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d>\n",n+1,employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
n++;
}
fclose(fp);
printf("目前共有%d个职工\n",n);
printf("按任意键返回");
}
addemploy()
{
FILE *fp;
char choice='y';
int i=1;
fp=fopen("employ.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("请你输入职工号码\n");
scanf("%d",&employ[i].employnum);
printf("请你输入职工名\n");
scanf("%s",employ[i].employname);
printf("请输入职工年龄\n");
scanf("%d",&employ[i].employage);
printf("请你输入性别\n");
scanf("%s",employ[i].employsex);
printf("请你输入职工的学历水平\n");
scanf("%s",employ[i].employleve);
printf("请输入职工的工资\n");
scanf("%d",&employ[i].employtage);
fwrite(&employ[i],sizeof(struct employ),1,fp);
printf("是否要输入下个职工信息?\n");
scanf("%s",&choice);
}
printf("按任意键返回\n");
fclose(fp);
}