求高手帮忙找错,三个函数体哪里错了???
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#define LEN sizeof(struct node)
#define N 100
#define PF printf
#define SF scanf
struct books
{
int booknum; //书号
char bookname[20];//书名
char authorname[20];//作者
char publish[20]; //出版社
int price; //价格
};
struct node
{
struct books book;
struct node *next;
};
typedef struct node NODE;
NODE *luru(NODE *head)//录入函数
{
NODE *p;
head=NULL;
while(1)
{
char ch;
p=(NODE*)malloc(LEN);
PF("~~~~~~~~~~~~~~~开始输入信息~~~~~~~~~~~~~\n");
PF("请输入书的编号:");
SF("%d",&p->book.booknum);
PF("\n");
PF("请输入出版社:");
SF("%s",&p->book.publish);
PF("\n");
PF("请输入图书价格:");
SF("%d",&p->book.price);
PF("\n");
PF("请输入书名:");
SF("%s",&p->book.bookname);
PF("\n");
PF("请输作者名:");
SF("%s",&p->book.authorname);
getchar( );//屏蔽回车
PF("是否继续输入,请选择(y/n):");
SF("%c",&ch);
if(ch=='n')
break;
else
p=p->next;
}
PF("输入信息成功!\n");
return head;
}
NODE *search(NODE *head)//按书名查询
{
char name[20];
int pd=1;
NODE *p;
p=(NODE*)malloc(LEN);
PF("请输入要查询的书名:");
SF("%s",name);
do
{
p=p->next;
pd=strcmp(name,p->book.bookname);
}
while(pd=0);
PF("%d\t%s\t%s\t%d\t%s\n",p->book.booknum,p->book.bookname,p->book.publish,p->book.price,p->book.authorname);
}
NODE *delsh(NODE *head)//按书号删除
{
int x;
NODE *current,*front;
PF("请你输入想要删除图书的书号\n");
SF("%d",&x);
while(x>N)
{
PF("您要删除的图书信息不存在,请重新输入!\n");
return 0;
}
if(head==NULL)
PF("\n Empty.");
else
{
current=head;
while((x!=current->book.booknum)&&(current->next!=NULL))
{
front=current;
current=current->next;
}
if(x==current->book.booknum)
{
if(current==head)
head=current->next;
else
front->next=current->next;
free(current);
PF("删除图书信息成功!\n");
}
else
PF("\n Not found.");
}
return head;
}
NODE *delsm(NODE *head)//按书名删除
{
NODE *current, *front;
char bookname;
PF("请输入你要删除的书名:");
SF("%s",bookname);
if(head==NULL)
PF("\n Empty.");
else
{
int x;
current=head;
while((x!=current->book.booknum)&&(current->next!=NULL))
{
front=current;
current=current->next;
}
if(x==current->book.booknum)
{
if(current==head)
head=current->next;
else
front->next=current->next;
free(current);
PF("删除图书信息成功!\n");
}
else
PF("\n Not found.");
}
return head;
}
int del(struct node *book)//删除信息
{
int h;
system("cls");
PF("~~~~~~~~~~~~~~~~图书信息删除~~~~~~~~~~~~~~~\n");
PF("|1.图书的书号|\n");
PF("|2.图书的书名|\n");
PF("请输入序号选择删除方式:");
SF("%d",&h);
switch(h)
{
case 1: delsh(book);break;//按书号删除
case 2: delsm(book);break;//按书名删除
default: PF("输入有误,请重新输入!\n");break;
}
}
void insert(NODE *head,struct books book)//插入信息
{
NODE *new,*front,*current;
new=(NODE*)malloc(LEN);
front=(NODE*)malloc(LEN);
current=(NODE*)malloc(LEN);
PF("请输入你想要插入的书籍信息(书号、书名、出版社、价格、作者名):");
SF("%d\t%s\t%s\t%d\t%s\n",new->book.booknum,new->book.bookname,new->book.publish,new-> book.price,new->book.authorname);
current=head;
while((current!=NULL)&&((current->book.price)<(new->book.price)))
{
front=current;
current=current->next;
}
new->book.booknum=book.booknum;
new->book.price=book.price;
strcpy(new->book.publish,book.publish);
strcpy(new->book.bookname,book.bookname);
strcpy(new->book.authorname,book.authorname);
new->next=current;
if(current==head)
head=new;
else
front->next=new;
}
void main(struct books book)
{
int choice,n=0;
NODE *head;
head=(NODE*)malloc(LEN);
head->next=NULL;
do
{
PF("\t\t*****************图书信息管理系统*****************\n");
PF("\t\t*\t\t|1.图书信息录入 *\n");
PF("\t\t*\t\t|2.图书信息查询 *\n");
PF("\t\t*\t\t|3.图书信息的删除 *\n");
PF("\t\t*\t\t|4.图书信息的插入 *\n");
PF("\t\t*\t\t|5.退出系统 *\n");
PF("\t\t*****************图书信息管理系统*****************\n\n\n");
PF("\t\t请输入以上序号进行选择:\n");
SF("%d",&choice);
switch(choice)
{
case 1: luru(head);break;//录入
case 2: search(head);break; //查询
case 3: del(head);break;//删除
case 4: insert(head,book);break;//插入
case 5: exit(0);
default :PF("输入有误,请重新输入!\n");break;
}
getchar();
}
while(1);
}
虽然整个程序没有语法错误,
但是search(),del(),insert()函数内部有什么问题,为什么执行不起来?