# include & ltstdio.h & gt# include & ltstdlib.h & gt# include & ltstring.h & gt# include & ltconio.h & gt结构ima { int id茶

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & ltstring.h & gt

# include & ltconio.h & gt

结构ima

{

int id

char name[20];

炭化产物〔30〕;

int数;

浮动价格;

};

void Append();

void sell delete();

void Amend();

void Findin();

void Browse()。

void colorsetting();

void end program();

void初始化()

{

FILE * fp

Struct ima i={1,"花生牛奶","湖北武汉",1200,2.5 };

Fp=fopen("ima.dat evil "," W ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试...................................................................................................................................................

退出(0);

}

fwrite(& amp;I,sizeof(struct ima),1,FP);

fclose(FP);

}

无效菜单()

{

int选择;

超市库存管理系统

Printf (" -系统菜单显示如下。

printf(" \ n \ t 1 = = = = = = = = = = = = = = = = = = = = = = =新购买的物品入库\ n ");

printf(" \ n \ T2 = = = = = = = = = = = = = = = = = = =项目信息已删除\ n ");

printf(" \ n \ T3 = = = = = = = = = = = = = = = = = = =项目信息修改\ n ");

printf(" \ n \ T4 = = = = = = = = = = = = = = = = = = =物品信息查询\ n ");

printf(" \ n \ t5 = = = = = = = = = = = = = = = = = = = =浏览物品信息\ n ");

printf(" \ n \ T6 = = = = = = = = = = = = = = = = = = = = =应用程序退出\ n ");

printf(" \ n \ t请输入您要选择的菜单...");

scanf("%d ",& amp选择);

开关(选择)

{

案例1:

append();

打破;

案例二:

sell delete();

打破;

案例三:

amend();

打破;

案例4:

findin();

打破;

案例5:

browse();

打破;

案例6:

end program();

打破;

默认值:

printf(" \ n \ t \ t \ t \ t \ t输入无效,请重新输入...");

getch();

系统(“cls”);

menu();

}

}

int validateID(int id)

{

FILE * fp

结构IMA I;

fp=fopen("ima.date "," r ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试...................................................................................................................................................

退出(0);

}

弗雷德(& ampI,sizeof(struct ima),1,FP);

而(!feof(fp))

{

if(i.id==id)

{

fclose(FP);

返回1;

打破;

}

弗雷德(& ampI,sizeof(struct ima),1,FP);

}

fclose(FP);

返回0;

}

void追加()

{ struct IMA I;

char选择;

FILE * fp

fp=fopen("ima.date "," ab ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试...................................................................................................................................................

退出(0);

}

labID:

printf(" \ n \ t请输入要入库的项目信息...\ n ");

printf(" \ t \ t \ t \ tItem number:");

scanf("%d ",& ampI . id);

if(validateID(i.id)==1)

{

printf(" \ t \ t \ t \ t该号码已被使用,请重新输入...");

goto labID

}

printf(" \ t \ t \ t \ t项目名称:");

scanf("%s ",I . name);

Printf("\t\t\t\t物品生产地:");

scanf("%s ",I . produce);

printf(" \ t \ t \ t项目数量:");

scanf("%d ",& amp编号);

printf(" \ t \ t \ t \ t该项目的单位价格:");

scanf("%f ",& ampI .价格);

fwrite(& amp;I,sizeof(struct ima),1,FP);

fclose(FP);

printf(" \ t \ t \ t \ t \ t \ t项目信息已成功接收!!!\ n ");

printf(" \ n是否要继续?(y/n)");

scanf(" %c ",& amp选择);

if(choice=='Y'||choice=='y ')

{

append();

}

其他

{

系统(“cls”);

menu();

}

}

void Selldelete()

{ struct IMA I[1000];

结构ima温度;

int delID

char选择;

int index = 0;

int j = 0;

FILE * fp

fp=fopen("ima.date "," r ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试............................................................................."));

退出(0);

}

弗雷德(& amptemp,sizeof(struct ima),1,FP);

而(!feof(fp))

{

I[index]= temp;

index++;

弗雷德(& amptemp,sizeof(struct ima),1,FP);

}

fclose(FP);

printf(" \ n \ t请输入要删除的项目的编号:");

scanf("%d ",& ampdelID);

fopen("f:\\ima.date "," w ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试............................................................................."));

退出(0);

}

for(j = 0;j & lt指数;j++)

{

if(i[j]。id!=delID)

{

fwrite(& amp;i[j],sizeof(struct ima),1,FP);

}

}

fclose(FP);

printf(" \ t \ t \ t \ t \ t项目信息已被清除!!!\ n ");

printf(" \ n是否要继续?(y/n)");

scanf(" %c ",& amp选择);

if(choice=='Y'||choice=='y ')

{

sell delete();

}

其他

{

系统(“cls”);

menu();

}

}

void修正()

{ int index = 0;

int ID,j;

char选择;

struct IMA I[1000];

结构ima温度;

FILE * fp

fp=fopen("ima.date "," r ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试...................................................................................................................................................

退出(0);

}

弗雷德(& amptemp,sizeof(struct ima),1,FP);

而(!feof(fp))

{

I[index]= temp;

index++;

弗雷德(& amptemp,sizeof(struct ima),1,FP);

}

fclose(FP);

fp=fopen("ima.date "," w ");

if(fp==NULL)

{

printf(" \ \ t \ t \ t系统错误,请再试一次...........................................................................);

退出(0);

}

printf(" \ n \ t请输入要修改的信息的项目编号:");

scanf("%d ",& ampID);

for(j = 0;j & lt= index-1;j++)

{

if(i[j]。id!=ID)

{

fwrite(& amp;i[j],sizeof(struct ima),1,FP);

}

其他

{

Printf ("\ t \ tItem名称更改为:");

scanf("%s ",i[j].姓名);

printf(" \ t \ t物品生产地变更为");

scanf("%s ",i[j].产生);

printf(" \ t \ t项目数量更改为");

scanf("%d ",& amp我[j]。号);

printf(" \ t \ t商品单价改为");

scanf("%f ",& amp我[j]。价格);

fwrite(& amp;i[j],sizeof(struct ima),1,FP);

}

}

fclose(FP);

printf(" \ t \ t \ t \ t项目信息已被修改...");

printf(" \ n是否要继续?(y/n)");

scanf(" %c ",& amp选择);

if(choice=='Y'||choice=='y ')

{

amend();

}

其他

{

系统(“cls”);

menu();

}

}

void Findin()

{

FILE * fp

int findIDchar选择;结构IMA I;

fp=fopen("ima.date "," r ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试...................................................................................................................................................

退出(0);

}

finID:

printf(" \ n \ t请输入要查询的项目编号...");

scanf("%d ",& ampfindID);

弗雷德(& ampI,sizeof(struct ima),1,FP);

而(!feof(fp))

{

if(i.id==findID)

{

Printf ("\ n \ n \ t * * * * * * * * * * *项目信息* * * * * * * * * * * *);

printf(" \ n \ t项目编号...%30d\n ",I . id);

printf(" \ n \ t-");

printf(" \ n \ t项目名称...%30s\n ",I . name);

printf(" \ n \ t-");

printf(" \ n \ t制造商...%30s\n ",I . produce);

printf(" \ n \ t-");

printf(" \ n \ t导入的数量...%30d\n ",识别号);

printf(" \ n \ t-");

printf(" \ n \ t批发价格...%30.3f\n ",I . price);

printf(" \ n \ t-");

printf(" \ n是否要继续?(y/n)");

scanf(" %c ",& amp选择);

if(choice=='Y'||choice=='y ')

{

findin();

}

其他

{

系统(“cls”);

menu();

}

}

弗雷德(& ampI,sizeof(struct ima),1,FP);

}

fclose(FP);

printf(" \ t \ t \ t \ t \ t输入的号码不存在,请重新输入...");

goto finID

}

void浏览()

{ struct IMA I;

int index = 0;

char选择;

FILE * fp

fp=fopen("ima.date "," r ");

if(fp==NULL)

{

printf(" \ t \ t \ t系统错误,请重试...................................................................................................................................................

退出(0);

}

弗雷德(& ampI,sizeof(struct ima),1,FP);

而(!feof(fp))

{

index++;

printf(" \ n \ n \ t * * * * * * * * * * * * *项目信息% d * * * * * * * * * * ",index);

printf(" \ n \ t项目编号...%30d\n ",I . id);

printf(" \ n \ t-");

printf(" \ n \ t项目名称...%30s\n ",I . name);

printf(" \ n \ t-");

printf(" \ n \ t制造商...%30s\n ",I . produce);

printf(" \ n \ t-");

printf(" \ n \ t导入的数量...%30d\n ",识别号);

printf(" \ n \ t-");

printf(" \ n \ t批发价格...%30.3f\n ",I . price);

printf(" \ n \ t-");

getch();

弗雷德(& ampI,sizeof(struct ima),1,FP);

}

fclose(FP);

printf(" \ n是否要继续?(y/n)");

scanf(" %c ",& amp选择);

if(choice=='Y'||choice=='y ')

{

browse();

}

其他

{

系统(“cls”);

menu();

}

}

void Endprogram()

{ char choice

系统(“cls”);

printf(" \ n \ n \ n \ n \ n \ n \ t \ t您确定要退出系统吗?\ n \ n \ n \ t \ t如果要退出,请按“y”键,其他键将返回主菜单... ");

scanf(" %c ",& amp选择);

if(choice=='Y'||choice=='y ')

{

系统(“cls”);

printf(" \ n \ n \ n \ n \ n \ n \ n \ n \ n \ t \ t \ t感谢您的使用!!!");

printf(" \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n ");

}

其他

{

系统(“cls”);

menu();

}

}

void main()

{

printf(" \ n \ n ");

printf(" \ t \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

Printf("\t\3欢迎\ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

Printf("\t\3超市库存管理系统\ 3 \ n ");

Printf("\t\3按任意键继续\ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ n ");

printf(" \ t \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3);

getch();

系统(“cls”);

menu();

初始化();

menu();

}