📄 createfile.c
字号:
#include "TypeDef.h"
#include "Function.h"
#include <stdio.h>
#include <string.h>
//*****添加图书主数据库记录************************
void AddDbRec(BookDbFile *bf, BnoIdxFile *bif, BnameIdxFile *bnif, BauthorIdxFile *baif, BpressIdxFile *bpif)
{
char choice;
int flag = 0; //是否继续输入
BookRecType newBook;
while(flag == 0)
{
system("cls");
printf("请输入书号(4位):");
scanf("%s", newBook.bno);
while(strlen(newBook.bno) != 4)
{
printf("输入书号位数不正确,请重新输入:");
scanf("%s", newBook.bno);
}
while(BinSearch(bif, newBook.bno) != 0)
{
printf("您输入的书号已存在,主键不能重复,请重新输入:");
scanf("%s", newBook.bno);
while(strlen(newBook.bno) != 4)
{
printf("输入书号位数不正确,请重新输入:");
scanf("%s", newBook.bno);
}
}
printf("请输入书名:");
scanf("%s", newBook.bname);
printf("请输入作者:");
scanf("%s", newBook.author);
printf("请输入出版社:");
scanf("%s", newBook.press);
printf("请输入分类(3位):");
scanf("%s", newBook.sortno);
while(strlen(newBook.sortno) != 3)
{
printf("输入分类号位数不正确,请重新输入:");
scanf("%s", newBook.sortno);
}
printf("请输入藏书量:");
scanf("%d", &newBook.storenum);
newBook.borrownum = 0;
ChangeBnoIdx(&newBook, bif, bf->len + 1);
ChangeBnameIdx(&newBook, bnif, bf->len + 1);
ChangeBauthorIdx(&newBook, baif, bf->len + 1);
ChangeBpressIdx(&newBook, bpif, bf->len + 1);
bf->BookDbase[bf->len + 1] = newBook;
bf->len ++;
while(1)
{
printf("是否继续添加书目?(Y/N)");
choice = getchar();
if(choice == 10) //判断接收的是否为回车符
{
choice = getchar();
}
if(choice == 'Y' || choice == 'y')
{
break;
}
else if(choice == 'N' || choice == 'n')
{
flag = 1;
break;
}
}
}
}
//*************************************************
//*****修改书号索引表******************************
void ChangeBnoIdx(BookRecType *newbook, BnoIdxFile *bif, int storeno)
{
strcpy(bif->BnoIdx[bif->len].bno, newbook->bno);
bif->BnoIdx[bif->len].RecNo = storeno;
bif->len++;
}
//*************************************************
//*****修改书名索引以及书名链头索引表**************
void ChangeBnameIdx(BookRecType *newbook, BnameIdxFile *bnif, int storeno)
{
int i = 0;
if(BnameFind(bnif, newbook->bname) > 0) //已存在同名的书
{
for(i = 0; i < bnif->len; ++i)
{
if(strcmp(newbook->bname, bnif->BnameIdx[i].bname))
{
newbook->namenext = bnif->BnameIdx[i].head;
bnif->BnameIdx[i].head = storeno;
bnif->BnameIdx[i].RecNum++;
break;
}
}
}
else //不存在同名的书
{
strcpy(bnif->BnameIdx[bnif->len].bname, newbook->bname);
bnif->BnameIdx[bnif->len].RecNum = 1;
bnif->BnameIdx[bnif->len].head = storeno;
newbook->namenext = 0;
bnif->len++;
}
}
//*************************************************
//*****修改作者索引以及作者链头索引表**************
void ChangeBauthorIdx(BookRecType *newbook, BauthorIdxFile *baif, int storeno)
{
int i = 0;
if(BauthorFind(baif, newbook->author) > 0) //已存在同作者的书
{
for(i = 0; i < baif->len; ++i)
{
if(strcmp(newbook->author, baif->BauthorIdx[i].author) == 0)
{
newbook->authnext = baif->BauthorIdx[i].head;
baif->BauthorIdx[i].head = storeno;
baif->BauthorIdx[i].RecNum++;
break;
}
}
}
else //不存在同作者的书
{
strcpy(baif->BauthorIdx[baif->len].author, newbook->author);
baif->BauthorIdx[baif->len].RecNum = 1;
baif->BauthorIdx[baif->len].head = storeno;
newbook->authnext = 0;
baif->len++;
}
}
//*************************************************
//*****修改出版社索引以及出版社链头索引表**********
void ChangeBpressIdx(BookRecType *newbook, BpressIdxFile *bpif, int storeno)
{
int i = 0;
if(BpressFind(bpif, newbook->press) > 0) //已存在同出版社的书
{
for(i = 0; i < bpif->len; ++i)
{
if(strcmp(newbook->press, bpif->BpressIdx[i].press) == 0)
{
newbook->prenext = bpif->BpressIdx[i].head;
bpif->BpressIdx[i].head = storeno;
bpif->BpressIdx[i].RecNum++;
break;
}
}
}
else //不存在同出版社的书
{
strcpy(bpif->BpressIdx[bpif->len].press, newbook->press);
bpif->BpressIdx[bpif->len].RecNum = 1;
bpif->BpressIdx[bpif->len].head = storeno;
newbook->prenext = 0;
bpif->len++;
}
}
//*************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -