程设小组作业——计算机配件的进货/销售管理系统

read.h 读取函数(读取文件)

////////////////////////////////////////////////// 
 /*
     读取信息创建链表并将信息存入链表 
 */  
 plink read(int type)
 {
     FILE fp;     
     plink p,node;     
     int i;     
     int month,day,hour,minute,part,model,mfts,num,name,judge_delete;     
     float total,unit;     char title_d;     
     switch(type){         
         case 1:             
             fp=fopen("../data/purchase_new.csv","r");               
             break;         
         case 2:             
             fp=fopen("../data/wholesale_new.csv","r");             
             break;         
         case 3:             
             fp=fopen("../data/retail_new.csv","r");     
     }     
     head=(plink)malloc(sizeof(link));//创建头节点      
     fscanf(fp,"%d,%d,%d,%d,%d,%d,%d,%f,%d,%f,%d,%d",&month,&day,&hour,&minute,&part,&model,&mfts,&unit,&num,&total,&name,&judge_delete);     
     head->time.month=month;     
     head->time.day=day;     
     head->time.hour=hour;     
     head->time.minute=minute;
     head->part=part;
     head->model=model;
     head->mfts=mfts;
     head->unit=unit;
     head->num=num;
     head->total=total;
     head->name=name;
     head->judge_delete=judge_delete;
     head->ll_time=head->time.month*1e6+head->time.day*1e4+head->time.hour*1e2+head->time.minute;
     head->next=NULL;
     p=head;
     while(!feof(fp))//当文件读取结束后,退出循环 
     { 
         node=(plink)malloc(sizeof(link));
         fscanf(fp,"%d,%d,%d,%d,%d,%d,%d,%f,%d,%f,%d,%d",&month,&day,&hour,&minute,&part,&model,&mfts,&unit,&num,&total,&name,&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->judge_delete=judge_delete;
         node->ll_time=node->time.month*1e6+node->time.day*1e4+node->time.hour*1e2+node->time.minute;
         p->next=node;
         node->next=NULL;
         p=node;
     }
     end=p;
     head=sort(head);
     fclose(fp);
     return head;
 }

点赞

发表评论