#include <stdio.h> #include <stdlib.h> #define MAXTLEN 70 #define MAXALEN 70 #define MAXBKS 10 struct book{ char title[MAXTLEN]; char author[MAXALEN]; float value; }; int main(){ struct book library[MAXBKS]; //图书馆 int count = 0, index, filecount; int size = sizeof(struct book); //这点值得注意 FILE *pbooks; if((pbooks = fopen("book.dat","a+b")) == NULL){ fputs("Can not open book.dat file ", stderr); exit(1); } rewind(pbooks); while(count < MAXBKS && fread(&library[count],size,1,pbooks) == 1){ if(count == 0){ puts("Current contents of book.dat: "); } printf("%s by %s: $%.2f ",library[count].title,library[count].author,library[count].value); count++; } filecount = count; if(count == MAXBKS){ fputs("The book.dat file is full",stderr); exit(2); } puts("please add the new book, title:"); while(count < MAXBKS && gets(library[count].title) != NULL && library[count].title[0] != '