结构体数组,scanf和fscanf 不能写入
定义了一个结构体数组,从文件里导入数据,使用fscanf函数,导入不了,然后我改成使用scanf函数直接输入数据也不能输入。错误提示:runtime error (press retry debug the application)。请问这是怎么回事?
typedef struct { char name[30]; char author[20]; int type; int price; }Book; FILE *fin,*fout; ////////////////////////// int main() { int j,i=1,n=0; Book books[20]; fin = fopen("books.txt","r"); fout = fopen("book.txt","a"); if(fin == NULL && fout == NULL) { printf("文件打开失败!\n"); exit(0); } // scanf("%s%s%d%f",books[i].name,books[i].author,&books[i].type,&books[i].price); // fprintf(fout,"%4s%4s%4d%4.2f",books[i].name,books[i].author,books[i].type,books[i].price); while (!feof(fin)) { // i++; fscanf(fout,"%s%s%d%f",books[i].name,books[i].author,&books[i].type,&books[i].price); i++; n++; } fclose(fin); fclose(fout); return 0; }