fwrite函数覆盖数据?????
void save(char book_num[],char book_name[],int num)
{ FILE *book_fp;
struct bk *t,*p;
p=l;
if((book_fp=fopen("C:\\Users\\zll\\Downloads\\book.txt","a+"))==NULL)
{ printf("不能建立图书文件!\n"); }
t=(struct bk *)malloc(sizeof(struct bk));
strcpy(t->book_num,book_num);
strcpy(t->book_name, book_name);
t->book_kc=t->book_xc=num;
p->next=t;p=t;
fwrite(t,sizeof(struct bk),1,book_fp);
fclose(book_fp);
}
void putin()
{
struct bk *p;
p=(struct bk *)malloc(sizeof(struct bk));
int number;
int y=1;
system("cls");
while(y)
{
printf("请输入您的书的编号:");
scanf("%s",p->book_num);
printf("请输入书名:");
scanf("%s",p->book_name);
printf("请输入您要存的数量:");
scanf("%d",&number);
save(p->book_num,p->book_name,number);
printf("\n是否继续录入(1.继续;0,退出录入):");
scanf("%d",&y);
switch(y)
{
case 1:putin();
break;
case 0:system("cls");menu();
break;
}
}
}
void search()
{ struct bk *p;
p=(struct bk *)malloc(sizeof(struct bk));
printf("请输入您的书的编号:");
scanf("%s",p->book_num);
while(p!=NULL&&strcmp(p->book_num,l->book_num)!=0)
{ l=l->next;
if(l==NULL) printf("\n\t此编号对应的图书不存在!\n");
}
printf("\n\t图书编号\t图书名\t库存量\t现存量 \n");
printf(" %10s\t %10s\t %d\t %d\t\n",l->book_num,l->book_name,l->book_kc,l->book_xc);
menu();
}