charu.h
来自「C语言写的商品信息管理系统 学习数据结构」· C头文件 代码 · 共 57 行
H
57 行
///////////////插入商品信息 3
int charu(struct shangpin shangp[],int count)
{
int j=0;
int bianhao=1;
struct shangpin shangptemb;
int weizhi=0;
printf("\n\t\t 提示:编号为0时,退出插入商品信息\n");
mylabe11:
printf("\n\t\t 请输入要插入的位置:");
scanf("%d",&weizhi);
if(weizhi>count+1)
{
printf("\n\t\t 插入位置错误!!\n");
goto mylabe11;
}
mylabe2:
printf("\n\t\t 请输入商品编号:");
scanf("%d",&shangptemb.id);getchar();
bianhao=jiancebianhao(shangp,shangptemb.id,count);// 检测是否存在相同的商品
if(bianhao==-1)
{
printf("\n\t\t 该编号已经存在!!\n");
goto mylabe2;
}
if(shangptemb.id==0) // 按0退出插入商品信息
return count;
printf("\n\t\t 请输入商品名:");
scanf("%s",&shangptemb.spname);getchar();
mylabel2:
printf("\n\t\t 请输入商品单价(元):");
scanf("%f",&shangptemb.price);getchar();
if(shangptemb.price<=0)
{
printf("\n\t\t 单价不可以小于等于0");
goto mylabel2;
}
mylabel3:
printf("\n\t\t 请输入商品库存:");
scanf("%d",&shangptemb.kucun);getchar();
if(shangptemb.kucun<0)
{
printf("\n\t\t 库存不可以小于0");
goto mylabel3;
}
for(j=count;j>weizhi-1;j--)
{
shangp[j]=shangp[j-1];
}
shangp[weizhi-1]=shangptemb;
count++;
printf("\n\t\t 插入完成,按任意键继续其他操作....");
getchar();
return count;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?