超市商品管理系统代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

超市商品管理系统

中文提示

By AzxXINER

#include

#include

#include

#include

//------------------------------------------------------------- //Max count of good,def 100 temporary

//------------------------------------------------------------- #define MAX 100

int current_cnt = 0;

//------------------------------------------------------------- //Good Information Definition

//------------------------------------------------------------- typedef struct GoodInfo{

char good_id[30];

char good_name[30];

char good_price[10];

char good_discount[10];

int good_amount;

int good_remain;

}GoodInfo;

GoodInfo *Goods[MAX];

//------------------------------------------------------------- //free goodinfo memory

//------------------------------------------------------------- void freeGoodInfo()

{

int i = 0;

for(i = 0;i < MAX;i++)

free(Goods[i]);

Goods[i] = NULL;

}

//-------------------------------------------------------------

//read a goodinfo from file

//------------------------------------------------------------- GoodInfo* readGoodInfo(FILE* fp)

{

GoodInfo* pGoodInfo = (GoodInfo*)malloc(sizeof(GoodInfo));

fscanf(fp,"%s",&pGoodInfo->good_id);

fscanf(fp,"\t%s",&pGoodInfo->good_name);

fscanf(fp,"\t%s",&pGoodInfo->good_price);

fscanf(fp,"\t%s",&pGoodInfo->good_discount);

fscanf(fp,"\t%d",&pGoodInfo->good_amount);

fscanf(fp,"\t%d\n",&pGoodInfo->good_remain);

return pGoodInfo;

}

//-------------------------------------------------------------

//check whether the file exists or not

//-------------------------------------------------------------

int check_nullfile()

{

FILE *fp = fopen("F:\\课程\\C语言程序设计\\综合实验2超市商品管理系统\\goodinfo.txt","r");

//file not exist

if(!fp){

printf("商品信息初始化文件不存在!\n请您放到E盘根目录!\n");

fp = fopen("F:\\课程\\C语言程序设计\\综合实验2超市商品管理系统\\goodinfo.txt","w");

fclose(fp);

}

//file already exist

else{

int temp;

//res for try to read file if file null feof() can't jarge if file is null

int res = fscanf(fp,"%d",&temp);

fclose(fp);

if(res<=0)

return -1;

else

return 1;

}

}

//-------------------------------------------------------------

//initialize

//-------------------------------------------------------------

void info_init()

{

int i = 0,j = 0;

int res = check_nullfile();

FILE *fp = fopen("F:\\课程\\C语言程序设计\\综合实验2超市商品管理系统\\goodinfo.txt","r");

for(i=0; i

Goods[i] = NULL;

}

while( res == 1 && !feof(fp) ){

Goods[j] = readGoodInfo(fp);

j++;

current_cnt++;

}

fclose(fp);

}

//-------------------------------------------------------------

//write one goodinfo into file

//-------------------------------------------------------------

void writeGoodInfo(FILE* fp,GoodInfo* pGoodInfo)

{

fprintf(fp,"%s\t",pGoodInfo->good_id);

fprintf(fp,"%s\t",pGoodInfo->good_name);

fprintf(fp,"%s\t",pGoodInfo->good_price);

fprintf(fp,"%s\t",pGoodInfo->good_discount);

fprintf(fp,"%d\t",pGoodInfo->good_amount);

fprintf(fp,"%d\n",pGoodInfo->good_remain);

}

//-------------------------------------------------------------

//write all goodinfos into file

//-------------------------------------------------------------

void info_flush()

{

int i = 0;

FILE *fp = fopen("F:\\课程\\C语言程序设计\\综合实验2超市商品管理系统\\goodinfo.txt","w");

相关文档
最新文档