请教下,这个程序为何不能将数据写入文件
#include<stdio.h>
#include<stdlib.h>
#define MAXTITL 40
#define MAXAUTL 40
#define MAXBKS 5 //图书的本数
struct book{
char title[MAXTITL];
char author[MAXAUTL];
float value;
};
int main(void)
{
struct book library[MAXBKS];
int count=0,i,filecount;
FILE *fpb;
int size=sizeof(struct book);
if((fpb=fopen("book.txt","ab+"))==NULL)
{
puts("can't open file");
exit (1);
}
rewind(fpb); //定位到文件开始
while(count<MAXBKS&&fread(&library[count],size,1,fpb)==1)
{
if(count==0)
puts("current contents of the book");
printf("%s by %s:$%.2f\n",library[count].title,library[count].author,library[count].value);
count++;
}
filecount=count;
if(count==MAXBKS)
exit(1);
while(count<MAXBKS&&gets(library[count].title)!=NULL&&library[count].title[0]!='\0')
{
puts("enter the author");
gets(library[count].author);
puts("enter the value");
scanf("%f",&library[count++].value);
while(getchar()!='\n') //清空输入行
continue;
if(count<MAXBKS)
puts("enter the next title");
}
if(count>0)
{
puts("here is the book list");
for(i=0;i<count;i++)
printf("%s by %s:$%.2f\n",library[i].title,library[i].author,library[i].value);
fwrite(&library[filecount],count-filecount,1,fpb);
}
else
puts("no books");
puts("bye");
fclose(fpb);
}