有大佬可以给我写一下图书入库分函数吗?

那么data.txt文件中需要先保存一个整数bookNum,然后再保存bookNum个Book类型的数据(来自数组bk。)

 

读取的时候,也是先读取整数到bookNum,然后在文件中连续读取bookNum个单元(Book类型)到数组bk。

 

 

 

读取的部分代码大致如下:(保存的代码可以参考该方式,使用fwrite函数)

 

ReadData(){

        FILE *fp;

 

        if((fp=fopen(".\\data.txt","rb"))==NULL)

 

               {printf("Can not open the file!\n");return;} 

 

         fread(&bookNum,sizeof(int),1,fp);

 

        fread(bk,sizeof(Book),bookNum,fp); 

 

        fclose(fp);

 

}这是我的部分代码

 

#include<stdio.h>

 

#include<stdlib.h>

 

#include<conio.h>

 

#include<string.h>

 

#include<io.h>

 

#define MAXNUM 2000

 

typedef struct{

char isbn[10];//书序号 

 

char bkName[30];//书名

 

char author[20];//作者

 

float price;//单价

 

int num;//数量

 

} Book;

 

int bookNum=3;

 

Book bk[MAXNUM]={"001","C Primer Plus","Stephen Prata",89.00,10,

 

"002","python","John zelle",78.00,20,

 

"003","The Dream of Red Mansion","CaoXueQin",38.00,30};

 

void input(){

system("cls");

 

有哪位大佬可以按上面的方法给我写一下吗?谢谢!

 

 

用到上面提示的代码,写一个图书入库的分