|
|
|
@ -134,3 +134,63 @@ void print_data()
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新图书信息
|
|
|
|
|
void update_data()
|
|
|
|
|
{
|
|
|
|
|
int id;
|
|
|
|
|
struct book *p;
|
|
|
|
|
|
|
|
|
|
printf("请输入要修改的图书编号:");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
p = find(id); // 查找编号为id的图书
|
|
|
|
|
if(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("请依次输入修改后的图书信息:\n");
|
|
|
|
|
printf("图书名称:");
|
|
|
|
|
scanf("%s", p->name);
|
|
|
|
|
printf("图书作者:");
|
|
|
|
|
scanf("%s", p->author);
|
|
|
|
|
printf("图书价格:");
|
|
|
|
|
scanf("%f", &p->price);
|
|
|
|
|
|
|
|
|
|
printf("图书信息修改成功!\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("没有找到编号为%d的图书!\n", id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除图书信息
|
|
|
|
|
void delete_data()
|
|
|
|
|
{
|
|
|
|
|
int id;
|
|
|
|
|
struct book *p, *q;
|
|
|
|
|
|
|
|
|
|
printf("请输入要删除的图书编号:");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
p = books;
|
|
|
|
|
q = NULL;
|
|
|
|
|
while(p != NULL && p->id != id)
|
|
|
|
|
{
|
|
|
|
|
q = p;
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
if(p != NULL) // 找到该节点
|
|
|
|
|
{
|
|
|
|
|
if(q == NULL) // 第一个节点
|
|
|
|
|
books = p->next;
|
|
|
|
|
else
|
|
|
|
|
q->next = p->next;
|
|
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
|
printf("图书信息删除成功!\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("没有找到编号为%d的图书!\n", id);
|
|
|
|
|
}
|
|
|
|
|
}
|