天天看點

批量導入圖書資訊

一個簡單的圖書系統中對書本資訊進行批量導入

//批量導入圖書資訊

void loads_book(){

printf(“請輸入檔案路徑:”);

char filepath[40] = {};

scanf("%s",filepath);

FILE *fp = fopen(filepath,“r”);

if(fp == NULL){

printf(“請檢查檔案是否存在!\n”);

return;

}

struct Book b = {};

//書名 作者 出版時間(year,mon,day) 出版社 售價

printf(“書名 作者 出版時間(year,mon,day) 出版社 售價\n”);

int year=0,mon=0,day=0;

while(fscanf(fp,"%s %s %d %d %d %s %lf",b.name,b.author,&year,&mon,&day,b.press,&b.price)>=7){

b.no = makebookno++;

b.pubdate = gettime(year,mon,day);

add_book_memroy(b);

}

fclose(fp);
           

}

繼續閱讀