求大神解答,这个程序为什么会崩溃?
include<stdio.h>#include<string.h>
#include<stdlib.h>
typedef struct book
{
int number;
char name[50];
char writer[50];
char press[50];
int time;
float price;
struct book *next;
}BOOK;
BOOK *createbook()
{
int n,time,number;
char name[50],writer[50],press[50];
float price;
BOOK *p,*head,*tail;
head=tail=NULL;
printf("请输入新图书编号:");
scanf("%d",&number);
getchar();
if(number==0)
{
return;
}
printf("请输入新图书书名:");
scanf("%s",&name);
getchar();
printf("请输入新图书作者:");
scanf("%s",&writer);
getchar();
printf("请输入新图书出版社:");
scanf("%s",&press);
getchar();
printf("请输入新图书出版时间:");
scanf("%s",&time);
getchar();
printf("请输入新图书价格:");
scanf("%f",&price);
getchar();
printf("ok!");
getchar();
//问题!!!!!!!!!!!
while(number!=0)
{
p=(BOOK *)malloc(sizeof(BOOK));
p->number=number;
strcpy(p->name,name);
strcpy(p->writer,writer);
strcpy(p->press,press);
p->time=time;
p->price=price;
p->next=NULL;
if(head=NULL)
{
head=p;
}
else
{
tail->next=p;
}
tail=p;
do
{
printf("请输入图书编号:");
scanf("%d",&number);
for(;head!=NULL;head->next)
{
if(head->number==number)
{
n=0;
}
}
if(n==0)
printf("您输入图书编号重复了,请重新输入!");
else
break;
}while(1);
if(number==0)
break;
else
{
printf("请输入新图书书名:");
scanf("%s",&name);
getchar();
printf("请输入新图书作者:");
scanf("%s",&writer);
getchar();
printf("请输入新图书出版社:");
scanf("%s",&press);
getchar();
printf("请输入新图书出版时间:");
scanf("%s",&time);
getchar();
printf("请输入新图书价格:");
scanf("%f",&price);
getchar();
printf("ok!");
getchar();
}
}
return head;
}
void main()
{
BOOK *head=NULL;
printf("注意!当输入图书编号为0时退出!");
head=createbook();
if(head==NULL)
printf("操作成功!\n");
}