read_gift.h 读取赠品记录函数:从文件读取记录并存入链表
////////////////////////////////////
/*
读取赠品记录函数:从文件读取记录并存入链表
*/
pglink read_gift()
{
FILE *fp;
pglink p,node;
int i;
int month,day,hour,minute,part,model,mfts,num,name,judge_delete,op_gift;
float total,unit;
char title_d;
fp=fopen("../data/gift_new.csv","r");
headg=(pglink)malloc(sizeof(glink));//创建头节点
fscanf(fp,"%d,%d,%d,%d,%d,%d,%d,%f,%d,%f,%d,%d,%d",&month,&day,&hour,&minute,&part,&model,&mfts,&unit,&num,&total,&name,&op_gift,&judge_delete);
headg->time.month=month;
headg->time.day=day;
headg->time.hour=hour;
headg->time.minute=minute;
headg->part=part;
headg->model=model;
headg->mfts=mfts;
headg->unit=unit;
headg->num=num;
headg->total=total;
headg->name=name;
headg->option_gift=op_gift;
headg->judge_delete=judge_delete;
headg->next=NULL;
p=headg;
while(!feof(fp))//当文件读取结束后,退出循环
{
node=(pglink)malloc(sizeof(glink));
fscanf(fp,"%d,%d,%d,%d,%d,%d,%d,%f,%d,%f,%d,%d,%d",&month,&day,&hour,&minute,&part,&model,&mfts,&unit,&num,&total,&name,&op_gift,&judge_delete);
fgetc(fp);
node->time.month=month;
node->time.day=day;
node->time.hour=hour;
node->time.minute=minute;
node->part=part;
node->model=model;
node->mfts=mfts;
node->unit=unit;
node->num=num;
node->total=total;
node->name=name;
node->option_gift=op_gift;
node->judge_delete=judge_delete;
p->next=node;
node->next=NULL;
p=node;
}
fclose(fp);
return headg;
}