图书信息包括:登录号、书名、作者名、分类号、出版单位、出版时间、价格等。试设计一图书信息管理系统,使之能提供以下功能:
(1)系统以菜单方式工作。
(2)图书信息录入功能--输入。
(3)图书信息浏览功能--输出。
(4)查询和排序功能:(至少一种查询方式)--算法。
按书名查询
按作者名查询
(5)图书信息的删除与修改。
(1)设计一个主函数和多个子函数,每个子函数完成一个相对独立的子功能。
(2)程序运行时,首先进行口令检查,再显示菜单。并能根据菜单调用相应的函数功能。
口令程序段的功能要求:
《1》提示用户输入一个口令。
《2》用户输入口令后,若口令对,则提示用户通过,可执行后续程序;否则不通过。
《3》可对用户的口令输入进行次数限制(如:重复输入3次都不对),则自动退出系统。
(3)显示数据时,一页显示不下,可分页显示。
#include /*引用库函数*/
#include
#include
#include
#include
#include
typedef struct book_info { //定义图书信息的结构体变量并声明新的类型名
char AN[10]; /*登录号*/
char name[20]; /*书名*/
char author[20]; /*作者名*/
char clc[10]; /*分类名*/
char company[20]; /*出版单位*/
char date[20]; /*出版日期*/
char price[10]; /*价格*/
struct book_info *next;
}Booklist, *Pointer;
int num = 0; //全局变量的定义
Pointer Head = NULL; //头指针为空
FILE *fp; //指向文件的指针
/*声明函数*/
int menu_select(); /*主菜单函数*/
void Insert(Pointer * Head); /*录入函数*/
void Scan(Pointer Head); /*显示函数*/
void Search_name(Pointer Head); /*按书名查找函数*/
void Search_author(Pointer Head); /*按作者名查找函数*/
void Listbyname(Pointer *Head); /*按书名排序函数*/
void Delete(Pointer * Head); //删除函数
void Update(Pointer Head); //修改函数
void Save(); //用文本文件形式保存函数
void Read(); //读入文本文件函数
void Exit(); //退出函数
int main() { //主函数
system("cls"); /*运行前清屏*/
for(;;) {
switch(menu_select()) {
case 1:Insert(& Head); break;
case 2:Scan(Head); break;
case 3:Search_name(Head); break;
case 4:Search_author(Head); break;
case 5:Listbyname(&Head); break;
case 6:Delete(&Head); break;
case 7:Update(Head); break;
case 8:Save(); break;
case 9:Read(); break;
case 0:Exit();
default:
putchar('\a');
}
}
return 0;
}
menu_select() { //主菜单函数
int a;
printf("\n\t\t\t欢迎使用图书信息管理系统\n\n\n\n\n\t\t ***** 请按任意键进入系统菜单! ***** \n");
getch();
system("cls");
printf("\t\t********************MENU*********************\n"); //主菜单
printf("\t\t 1. 录入图书信息\n");
printf("\t\t 2. 浏览图书信息\n");
printf("\t\t 3. 按书名查询图书信息\n");
printf("\t\t 4. 按作者名查询图书信息\n");
printf("\t\t 5. 图书信息排序\n");
printf("\t\t 6. 删除图书信息\n");
printf("\t\t 7. 修改图书信息\n");
printf("\t\t 8. 图书数据保存\n");
printf("\t\t 9. 图书信息文件打开\n");
printf("\t\t 0. 退出\n");
printf("\t\t***********************************************\n");
do {
printf("\n\t请选择您所需要的服务:");
scanf("%d",&a);
} while(a < 0 || a > 9);
return a;
}
void Insert(Pointer * Head) { //录入图书信息函数
char AN[10] ;
char c;
Pointer p, q, r;
printf("\n\t\t**************** 请输入图书信息 ****************\n"); /*交互输入*/
printf("\n\t\t请输入登录号:");
scanf("%s", AN);
p = q = *Head; //检测登录号是否重复
while(p != NULL) {
if(strcmp(p->AN, AN) == 0) {
printf ("已经有相同的登录号:");
return;
} else {
q = p;
p = p->next;
}
}
r = (Pointer)malloc(sizeof(Booklist));
r->next = NULL;
if(r == NULL) {
printf("分配空间失败!");
return;
}
if(q == NULL)
*Head = r;
else{
q->next = r;
}
strcpy(r->AN, AN);
printf("\n\t\t输入书名:"); //录入图书信息
scanf("%s", r->name);
getchar();
printf("\n\t\t输入作者名:");
scanf("%s", r->author);
getchar();
printf("\n\t\t输入分类号:");
scanf("%s", r->clc) ;
getchar();
printf("\n\t\t输入出版单位:");
scanf("%s", r->company) ;
getchar();
printf("\n\t\t输入出版日期:");
gets(r->date) ;
printf("\n\t\t输入价格:");
scanf("%s", r->price);
do{
printf("\n\t\t录入成功!!!!");
num++;
printf("选择是否继续录入(Y/N)?:"); /*连续录入图书信息*/
getchar();
scanf("%c", &c);
if(c == 'y' || c == 'Y')
Insert(Head);
else {
if(c == 'n' || c == 'N')
return;
else
printf("\n\t\t输入错误,请重新输入!!!");
}
} while(c != 'y' && c != 'n' && c != 'Y' && c != 'N');
}
void Scan(Pointer Head) { //显示图书信息函数
Pointer p;
p = Head;
if(p == NULL)
printf("记录为空"); //检测是否有图书信息
else {
printf("\n\t共有%d条记录",num);
while(p != NULL) {
printf("\n\n\t\t登录号:%-10s", p->AN); //显示图书信息
printf("\n\t\t书名: %-20s", p->name);
printf("\n\t\t作者名: %-20s", p->author);
printf("\n\t\t分类号: %-10s", p->clc);
printf("\n\t\t出版单位:%-20s", p->company);
printf("\n\t\t出版时间:%-20s", p->date);
printf("\n\t\t价格: ¥%-10s", p->price);
p = p->next;
}
printf("\n\t\t请按任意键回到主菜单");
return;
}
}
void Search_name(Pointer Head) { //按书名查找函数
int flag = 0; //标记变量的初值
char name[10];
Pointer p;
printf("\n请输入需要查询的书名:");
scanf("%s", name);
printf("\n\t\t************* 以下是您查找的信息 ***************");
p = Head;
while(p != NULL) {
if(strcmp(p->name, name) == 0) { //查找符合的图书
printf("\n\t登录号: %-10s", p->AN);
printf("\n\t书名: %-20s", p->name);
printf("\n\t作者名: %-20s", p->author);
printf("\n\t分类号: %-10s", p->clc);
printf("\n\t出版单位:%-20s", p->company);
printf("\n\t出版时间:%-20s", p->date);
printf("\n\t价格: ¥%-10s", p->price);
flag = 1; //找到标记变量设为1
p = p->next; //指针走到下一个节点
} else
p = p->next;
}
if(flag == 0)
printf("\n\t\t没有相同书名纪录");
printf("\n\t\t请按任意键返回主菜单");
getchar();
}
void Search_author(Pointer Head) { //按作者名查找函数
int flag = 0;
char author[10];
Pointer p;
printf("\n请输入需要查询的作者名:");
scanf("%s", author);
printf("\n\t\t************* 以下是您查找的信息 ***************");
p = Head;
while(p != NULL) { //查找符合的图书
if(strcmp(p->author, author) == 0) { /*找到图书显示信息*/
printf("\n\t登录号: %-10s", p->AN);
printf("\n\t书名: %-20s", p->name);
printf("\n\t作者名: %-20s", p->author);
printf("\n\t分类号: %-10s", p->clc);
printf("\n\t出版单位:%-20s", p->company);
printf("\n\t出版时间:%-20s", p->date);
printf("\n\t价格: ¥%-10s", p->price);
flag = 1;
p = p->next;
} else
p = p->next;
}
if(flag == 0)
printf("\n\t\t没有相同作者名纪录");
printf("\n\t\t请按任意键返回主菜单");
getch();
}
void Listbyname(Pointer *Head) { //按书名排序函数
Pointer p, q;
int i, j;
char t[10];
char c;
if(Head == NULL) {
printf("\n\t\t没有任何资料!\n");
return;
}
if(num == 0) { //检查是否存在数据可供排序
printf("\n\t\t图书信息记录为空!!请按任意键返回主菜单。");
getchar();
return;
}
p = q = *Head;
for(i = 0; i < num; i++) { //利用冒泡排序
for(j = i + 1; j < num; j++) {
q = p;
p = p->next; //使指针指向下一个结点
if(strcmp(q->name,p->name)>0) { //检查二者排序先后:p指针对应数据应排于q指针对应数据后,p,q进行数据交换
strcpy(t, p->AN);
strcpy(p->AN, q->AN);
strcpy(q->AN, t);
strcpy(t, p->author);
strcpy(p->author, q->author);
strcpy(q->author, t);
strcpy(t, p->clc);
strcpy(p->clc, q->clc);
strcpy(q->clc, t);
strcpy(t, p->company);
strcpy(p->company, q->company);
strcpy(q->company, t);
strcpy(t, p->date);
strcpy(p->date, q->date);
strcpy(q->date, t);
strcpy(t, p->name);
strcpy(p->name, q->name);
strcpy(q->name, t);
strcpy(t, p->price);
strcpy(p->price, q->price);
strcpy(q->price, t);
}
}
q = *Head;
p = *Head;
}
do {
printf("\n\t排序完成,是否显示(Y/N)?:"); /*询问是否显示排序结果*/
getchar();
scanf("%c", &c);
if(c == 'y' || c == 'Y')
Scan(*Head); //显示排序结果
else {
if(c == 'n' || c == 'N')
return; //返回主菜单
else
printf("\n\t\t输入错误,请重新输入!!!"); //错误则继续询问
}
} while(c != 'y' && c != 'n' && c != 'Y' && c != 'N');
}
void Delete(Pointer *Head) { /*删除函数*/
int flag = 1;
char AN[10];
char c, z;
Pointer p, q;
printf("\n\t\t******************* 图书删除 *******************\n");
printf("\t请输入要删除图书的信息的登录号:");
scanf("%s", AN);
p = q = *Head; /*查找符合条件的图书*/
while(p != NULL && flag) {
if(strcmp(p->AN, AN) == 0) { /*找到该图书*/
printf("\t\n登录号:%-10s", p->AN); //显示即将要删除的图书的信息
printf("\t\n书名:%-20s", p->name);
printf("\t\n作者名:%-20s", p->author);
printf("\t\n分类号:%-10s", p->clc);
printf("\t\n出版单位:%-20s", p->company);
printf("\t\n出版时间:%-20s", p->date);
printf("\t\n价格:¥%-10s\n", p->price);
printf("确定删除?确定请输Y,其它则不删除"); //询问是否删除
getchar();
scanf("%c", &z);
if(z == 'Y' || z == 'y') {
if(p == *Head) {
*Head = p->next;
free(p); /*删除图书信息*/
} else {
q->next = p->next;
free(p);
}
flag = 0;
} else {
printf("图书信息未删除,返回主菜单。");
return;
}
} else {
q = p;
p = p->next; /*指针走到下一个节点*/
}
printf("\t\t删除成功!!!\n");
}
if(flag)
printf("\t没有找到可以删除的数据!!!");
do {
printf("选择是否继续删除(Y/N)?:"); /*连续删除图书信息*/
getchar();
scanf("%c", &c);
if(c == 'y' || c == 'Y')
Delete(Head); /*继续删除*/
else {
if(c == 'n' || c == 'N')
return; /*不删除返回主菜单*/
else
printf("\n\t\t输入错误,请重新输入!!!");
}
} while(c != 'y' && c != 'n' && c != 'Y' && c != 'N');
}
void Update(Pointer Head) { /*图书信息修改函数*/
int flag = 1;
char AN[10];
char c;
Pointer p;
printf("\n\t\t***************** 图书信息修改 *****************\n");
printf("\t请输入要修改的图书的登录号:");
scanf("%s", AN); /*查找符合条件的图书*/
p = Head;
while(p != NULL && flag) {
if(strcmp(p->AN, AN) == 0) {
printf("\n\t\t请输入登录号:"); /*修改图书信息*/
scanf("%s", p->AN);
printf("\n\t\t输入书名:");
scanf("%s", p->name);
getchar();
printf("\n\t\t输入作者名:");
scanf("%s", p->author);
getchar();
printf("\n\t\t输入分类号:");
scanf("%s",p->clc) ;
getchar();
printf("\n\t\t输入出版单位:");
scanf("%s", p->company) ;
getchar();
printf("\n\t\t输入出版日期:");
gets(p->date);
printf("\n\t\t输入价格:");
scanf("%s", p->price);
flag = 0;
printf("修改成功!!\n");
} else
p = p->next; /*指针走到下一个节点*/
}
if(flag)
printf("\n\t\t没有该图书记录!!!");
do {
printf("选择是否继续修改(Y/N)?:"); /*连续修改图书信息*/
getchar();
scanf("%c", &c);
if(c == 'y' || c == 'Y')
Update(Head); /*继续修改*/
else {
if(c == 'n' || c == 'N')
return; //不修改,返回菜单
else
printf("\n\t\t输入错误,请重新输入!!!");
}
} while(c != 'y' && c != 'n' && c != 'Y' && c != 'N'); //输入错误则继续询问
}
void Save() { /*以文本文件形式保存的函数*/
Pointer p;
p = Head;
char file[20]; /*用来存放文件保存路径以及文件名*/
printf("请输入文件路径及文件名:");
scanf("%s", file);
if((fp = fopen(file, "w+")) == NULL) { /*判断能否打开文件*/
printf("不能打开文件!\n");
return;
}
while(p != NULL) {
fprintf(fp, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
p->AN, p->name, p->author, p->clc, p->company, p->date, p->price); //将数据写入文件
p = p->next; /*下移一个结点*/
}
fclose(fp); //写入完成,关闭文件
printf("文件已经保存!\n");
return;
}
void Read() { /*读入文本文件的函数*/
Pointer p, q;
int m = 0;
char file[20];
printf("请输入文件路径及文件名:");
scanf("%s", file); /*输入文件路径及名称*/
if((fp = fopen(file, "r+")) == NULL) { //检查文件是否存在
printf("不能打开文件!\n");
return;
}
m = m + 1;
if(m == 1) {
p = (Pointer)malloc(sizeof(Booklist)); /*开辟一个新单元*/
Head = p; //将p的地址赋给头指针Head
fscanf(fp, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n",
&p->AN, &p->name, &p->author, &p->clc, &p->company, &p->date, &p->price); /*文件读入*/
do {
num = num + 1; //记录书籍信息量
if(num == 1) //区别开链表开头与中间的处理方法
Head->next = p;
else
q->next = p;
q = p;
p = (Pointer)malloc(sizeof(Booklist)); /*开辟一个新单元*/
fscanf(fp,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n",
&p->AN, &p->name, &p->author, &p->clc, &p->company, &p->date, &p->price); //读入文件数据
} while(!feof(fp)); //检查文件是否结束,若是则停止读入,否则继续读入
q->next = p;
p->next = NULL; //链表结尾处理
num = num + 1; //正确的图书信息量
}
printf("写入数据成功,可返回浏览其信息。");
fclose(fp); /*结束读入,关闭文件*/
return;
}
void Exit() { /*退出程序的函数*/
char c;
do {
printf("\n\t\t退出中......是否保存到文件(Y/N)?"); /*询问是否保存图书信息,防止丢失*/
getchar();
scanf("%c", &c);
if(c == 'y' || c == 'Y') {
Save();
exit(0);
} else {
if(c == 'n' || c == 'N') {
exit(0);
} else
printf("\n\t\t输入错误,请重新输入!!!");
}
} while(c != 'y' && c != 'n' && c != 'Y' && c != 'N'); //错误则继续询问
}
// (1)主函数
void main() { /*主函数*/
struct library *head;
int d, i, b;
for(i = 0; i < 3; i++) {
printf("\n\n\n\n\n\n\n\n\n\n\n 请用户输入口令:");
scanf("%d", &d);
if(d != 111) {
printf("口令输入错误\n");
if(i == 2) {
printf(“你已经输入3次错误口令,系统自动关闭\n”);
exit(0);
}
else
break;
}
system("cls");
do {
switch(b = menu()){
case 1: head = creat();
save(head);
break;
case 2: out(head);
break;
case 3: check(head);
save(head);
break;
case 4: scores(head);
save(head);
out(head);
break;
case 5: del(head);
save(head);
out(head);
break;
case 6: corret(head);
save(head);
out(head);
break;
case 0: printf(“谢谢使用\n”);
exit(0);
default: printf(“你所选择功能不存在请重新选择\n”);
}
}while(b != 0);
}
}
// (2)菜单和初始化
int menu() { /*菜单*/
char *menu[] = {"\n\n\n\n\n\n ========图书信息管理系统==========\n\n",
" 1. 录入功能 ","2. 浏览功能 \n\n",
" 3. 查询功能 ","4. 排序功能 \n\n",
" 5. 删除功能 ","6. 修改功能 \n\n",
" 0. 退出系统\n\n",
" ==================================\n"};
int c, i;
for(i = 0; i < 9; i++)
printf("%s",menu[i]);
do {
printf("\n 请输入选项(0~6)并按回车键:");
scanf("%d",&c);
} while(c < 0 || c > 6);
return(c);
}
《(3)(录入函数) 》
int n;
struct library *creat(void) { /*建立链表*/
struct library *head;
struct library *p1, *p2;
n = 0;
system("cls");
printf(" 这是录入功能请输入图书数据\n");
p1 = p2 = (struct library *)malloc(LEN);
head = NULL;
while(1) {
printf("登录号:");
scanf("%ld", &p1->num);
if(p1->num != 0) {
printf("书名:");
scanf("%s", p1->bookname);
printf("作者名:");
scanf("%s", p1->author);
printf("类型号:");
scanf("%s", p1->type);
printf("出版单位");
scanf("%s", p1->publishing_house);
printf("出版时间:");
scanf("%s", p1->publishing_time);
printf("价格:");
scanf("%f", &p1->sale);
printf("\n");
n = n + 1;
if(n == 1)
head = p1;
else
p2->next = p1;
p2 = p1;
p1 = (struct library *)malloc(LEN);
} else
break;
}
p2->next = NULL;
return(head);
}
《(4)(保存函数) 》
void save(struct library *head) { /*保存文件*/
FILE *fp;
if((fp = fopen("library.dat", "wb")) == NULL) {
printf("不能打开文件\n");
exit(0);
}
do {
fwrite(head, sizeof(struct library), 1, fp);
head = head->next;
} while(head != NULL);
fclose(fp);
printf("\n文件已保存\n\n\n");
}
《(5)输出函数 》
struct library *out(struct library *head) { /*读入文件*/
FILE *fp;
struct library *p1, *p2;
if((fp = fopen("library.dat","rb")) == NULL) {
printf("不能打开文件\n");
exit(0);
}
fp = fopen("library.dat", "rb");
p1 = (struct library *)malloc(LEN);
head = p2 = p1;
printf("\n 图书的数据为\n");
while(!feof(fp)) {
fread(p1, sizeof(struct library), 1, fp);
printf(" 登录号:%ld", p1->num);
printf("书名:%s", p1->bookname);
printf("作者名:%s", p1->author);
printf("类型号:%s", p1->type);
printf("出版单位:%s", p1->publishing_house);
printf("出版时间:%s", p1->publishing_time);
printf("价格:%6.2f", p1->sale);
printf("\n");
if(p1->next == 0) break;
p1 = (struct library *)malloc(LEN);
p2->next = p1;
p2 = p1;
}
p2->next = 0;
fclose(fp);
return(head);
}
《(6)查询函数 》
struct library *check(struct library *head) { /*查询函数*/
struct library *p;
char style[10], a[10];
printf(" 这是图书查询功能\n");
printf(" 请输入查询的方法:");
scanf("%s", style);
printf(" 请输入要查询%s:",style);
scanf("%s", a);
printf("你所查询的数据:\n");
if(head == NULL) {
printf("\n该列表为空表\n");
goto end;
}
p = head;
if(p != 0) {
if(strcmp(style, "bookname") == 0) {
if(strcmp(a, p->bookname) == 0) {
printf(" 登录号:%ld", p->num);
printf("书名:%s", p->bookname);
printf("作者名:%s", p->author);
printf("类型号:%s", p->type);
printf("出版单位:%s", p->publishing_house);
printf("出版时间:%s", p->publishing_time);
printf("价格:%6.2f", p->sale);
printf("\n");
} else {
do {
p = p->next;
} while(strcmp(a, p->bookname) != 0 && p->next != NULL);
printf(" 登录号:%ld", p->num);
printf("书名:%s", p->bookname);
printf("作者名:%s", p->author);
printf("类型号:%s", p->type);
printf("出版单位:%s", p->publishing_house);
printf("出版时间:%s", p->publishing_time);
printf("价格:%6.2f", p->sale);
printf("\n");
}
}
if(strcmp(style, "author") == 0) {
if(strcmp(a, p->author) == 0) {
printf(" 登录号:%ld", p->num);
printf("书名:%s", p->bookname);
printf("作者名:%s", p->author);
printf("类型号:%s", p->type);
printf("出版单位:%s", p->publishing_house);
printf("出版时间:%s", p->publishing_time);
printf("价格:%6.2f", p->sale);
printf("\n");
} else {
do {
p = p->next;
} while(strcmp(a, p->author) != 0 && p->next != NULL);
printf(" 登录号:%ld",p->num);
printf("书名:%s",p->bookname);
printf("作者名:%s",p->author);
printf("类型号:%s",p->type);
printf("出版单位:%s",p->publishing_house);
printf("出版时间:%s",p->publishing_time);
printf("价格:%6.2f",p->sale);
printf("\n");
}
}
}
end: return(head);
}
《(7)排序函数 》
struct library *scores(struct library *head) { /*排序函数*/
struct library *p1, *p2;
float i;
long t;
char a[20], b[20], c[20], d[20], e[20];
p1 = head;
if(head == NULL) {
printf("该列表为空表\n");
} else {
while(p1 != NULL){
p2 = p1->next;
while(p2 != NULL) {
if(strcmp(p1->bookname, p2->bookname) >= 0) {
t = p2->num;
p2->num = p1->num;
p1->num = t;
i = p2->sale;
p2->sale = p1->sale;
p1->sale = i;
strcpy(a, p2->bookname);
strcpy(b, p2->author);
strcpy(c, p2->type);
strcpy(d, p2->publishing_house);
strcpy(e, p2->publishing_time);
strcpy(p2->bookname, p1->bookname);
strcpy(p2->author, p1->author);
strcpy(p2->type, p1->type);
strcpy(p2->publishing_house, p1->publishing_house);
strcpy(p2->publishing_time, p1->publishing_time);
strcpy(p1->bookname, a);
strcpy(p1->author, b);
strcpy(p1->type, c);
strcpy(p1->publishing_house, d);
strcpy(p1->publishing_time, e);
}
p2 = p2->next;
}
p1 = p1->next;
}
}
printf("文件已排序");
return(head);
}
《(8)修改函数 》
struct library *corret(struct library *head) { /*修改函数*/
struct library *p;
char m[10], z[10];
int b, x;
float y;
printf("请输入要修改的书名:");
scanf("%s", m);
if(head==NULL) {
printf("\n该列表为空表\n");
goto end;
}
p = head;
if(p != 0) {
while((strcmp(p->bookname, m) != 0) && p->next != NULL) {
p = p->next;
}
if(strcmp(p->bookname, m) == 0) {
printf("登录号:%ld", p->num);
printf("书名:%s", p->bookname);
printf("作者名:%s", p->author);
printf("类型号:%s", p->type);
printf("出版单位:%s", p->publishing_house);
printf("出版时间:%s", p->publishing_time);
printf("价格:%6.2f", p->sale);
printf("\n");
printf("请输入要修改的类型:\n1.登录号\n2.书名\n3.作者名\n4.分类号\n5.出版单位\n6.出版时间\n7.价格\n");
scanf("%d", &b);
printf("请输入修改信息:");
if(b == 1) {
scanf("%ld", &x);
p->num = x;
} else if (b == 7) {
scanf("%f", &y);
p->sale = y;
} else {
scanf("%s",z);
switch(b) {
case 2: strcpy(p->bookname, z);
break;
case 3: strcpy(p->author, z);
break;
case 4: strcpy(p->type, z);
break;
case 5: strcpy(p->publishing_house, z);
break;
case 6: strcpy(p->publishing_time, z);
break;
default:printf("发生错误\n");
}
}
}
}
printf("文件已修改");
end: return(head);
}
《(9)删除函数 》
struct library *del(struct library *head) { /*删除函数*/
struct library *p1, *p2;
long num;
if(head == NULL) {
printf("\n图书记录为空!\n");
goto end;
}
printf("请输入要删除的图书数据的登录号:");
scanf("%ld",&num);
while(num != 0) {
p1 = head;
while(num != p1->num && p1->next != NULL) {
p2 = p1;
p1 = p1->next;
}
if(num == p1->num) {
if(p1 == head)
head = p1->next;
else
p2->next = p1->next;
printf("删除:%ld\n", num);
} else
printf("%ld 找不到这个图书记录!\n", num);
scanf("%ld", &num);
}
printf("已删除信息");
end: return(head);
}