老子明天不想看代码
#include
#include
#define LEN sizeof(struct product)
struct product


{
int id;
char name[15];
char producer[15];
int date[15];
double price;
int amount;
};
struct product operate[100];


void ruku();


void chuku();


void shanchu();


void xiugai();


void chaxun();


int xianshi();
void ruku()
{
int i,n=0;
char a;
n=xianshi();
FILE *fp;
if((fp=fopen("product.txt","ab"))==NULL)
{
printf("can not open file\n");
}
printf("press n/y to continue:");

scanf("%c",&a);
while(a=='y')
{
for(i=0;i if(operate[i].id==operate[n].id)
{

printf("The id is existing,press any key to continue!");

fclose(fp);
}
printf("id:");
scanf("%d",&operate[n].id);
printf("name:");
scanf("%s",&operate[n].name);
printf("producer:");
scanf("%s",&operate[n].producer);
printf("date:");


scanf("%s",&operate[n].date);
printf("price:");
scanf("%lf",&operate[n].price);
printf("amount:");
scanf("%d",&operate[n].amount);
if(fwrite(&operate[n],LEN,1,fp)!=1)
{

printf("can not save!");
}
else
{

printf("product Id %d is saved!\n",operate[n].id);

n++;
}
printf("press n/y to continue input:");

scanf("%c",&a);
}
fclose(fp);
}
void chuku()
{
FILE *fp;
int id,i,n=0,j=0;
char a;
n=xianshi();
printf("please input the id:");
scanf("%d",&id);
for(i=0;i {
if(id==operate[i].id)
{

printf("find the product,press n/y to output:");

scanf("%c",&a);

if(a=='y')

{

printf("input the amount to output:");

scanf("%d",&j);

operate[i].amount=operate[i].amount-j;

if(operate[i].amount<0)

{

printf("the amount is less than your input and the amount is 0 now!\n");

operate[i].amount=0;

}

if((fp=fopen("product.txt","rb+"))==NULL)

{

printf("can not open file\n");

}

fseek(fp,i*LEN,0);

if(fwrite(&operate[i],LEN,1,fp)!=1)

{

printf("can not save file!\n");

}

fclose(fp);

printf("出库成功!\n");

}
}
}
printf("can not find the product!\n");
}
void shanchu()
{
FILE *fp;
int i,j,n=0,id;
n=xianshi();
printf("please input the id to delete:");
scanf("%d",&id);
for(i=0;i {
if(id==operate[i].id)
{

for(j=i;j

operate[j]=operate[j+1];

n--;

if((fp=fopen("product.txt","wb"))==NULL)

{

printf("can not open file\n");

}

for(j=0;j

if(fwrite(&operate[j],LEN,1,fp)!=1)

{

printf("can not save!");

}

fclose(fp);

printf("删除成功!\n");
}
}
printf("can not find the product!\n");
}
void xiugai()


{
FILE *fp;
int i,n=0,id;
n=xianshi();
printf("please input the id to xiugai:");
scanf("%d",&id);
for(i=0;i {
if(id==operate[i].id)


{

printf("find the product, you can xiugai!\n");

printf("id:");

scanf("%d",&operate[i].id);

printf("name:");

scanf("%s",&operate[i].name);

printf("producer:");

scanf("%s",&operate[i].producer);

printf("date:");

scanf("%s",&operate[i].date);

printf("price:");

scanf("%lf",&operate[i].price);

printf("amount:");

scanf("%d",&operate[i].amount);

if((fp=fopen("product.txt","rb+"))==NULL)

{

printf("can not open\n");

return;

}

fseek(fp,i*LEN,0);

if (fwrite(&operate[i],LEN,1,fp)!=1)

{

printf("can not save!");

getch();

}

fclose(fp);

printf("修改成功!\n");

xianshi();
}
}
printf("can not find information!\n");
}

void chaxun()


{
int id,i,n=0;
char a;
n=xianshi();
printf("please input the id:");
scanf("%d",&id);
for(i=0;i if(id==operate[i].id)


{
printf("find the product,press n/y to show:");

scanf("%c",&a);
if(a=='y')
{

printf("id

name

producer

date

price

amount\n");

printf("%-8d%-15s%-15s%-15s%-12.1lf%-8d\n",operate[i].id,operate[i].name,operate[i].producer,operate[i].date,operate[i].price,operate[i].amount);

/*将查找出的结果按指定格式输出*/
}
}
printf("can not find the product");


}

int xianshi()


{
int i,n=0;
FILE *fp;
if((fp=fopen("product.txt","rb"))==NULL)
{
printf("can not open file\n");


return -1;
}
while(!feof(fp))


if(fread(&operate[n],LEN,1,fp)==1)
n++;


fclose(fp);


if(n==0)


printf("No record in file!\n");
else


{
printf("id

name

producer

date

price

amount\n");
for(i=0;i {

printf("%-8d%-15s%-15s%-15s%-12.1lf%-8d\n",operate[i].id,operate[i].name,operate[i].producer,operate[i].date,operate[i].price,operate[i].amount);

/*将信息按指定格式打印*/
}
}
return n;
fclose(fp);


if (n==0)


printf("No record in file!\n");
else


{
printf("id

name

producer

date

price

amount\n");
for(i=0;i {

printf("%-8d%-15s%-15s%-15s%-12.1lf%-8d\n",operate[i].id,operate[i].name,operate[i].producer,operate[i].date,operate[i].price,operate[i].amount);

/*将信息按指定格式打印*/
}
}
return n;
}

int main(void)
{
int a,n;
printf(" 1. ru ku \n 2. chu ku \n 3. shan chu \n 4. xiu gai \n 5. cha xun \n 6. xian shi \n");
printf("Input one number(1~6):");
scanf("%d",&a);
while(a)
{
switch(a)
{

case 1:ruku();break;

case 2:chuku();break;

case 3:shanchu();break;

case 4:xiugai();break;

case 5:chaxun();break;

case 6:xianshi();break;

default:printf("error!\n");
}
scanf("%d",&a);
}
return 0;
}

#U先试用[超话]# 最近在这儿跟大家一起混得很快落!也收获了好多的,祝愿大家也跟我一样快落!评论点赞来告诉我你的快落,揪一个小姐妹送出图里的全部。(邮费自理)

有4片面膜,2个自然堂小眼霜7.5ml精华液,一个伊蒂之屋正装唇釉,一个INTO YOU正装唇釉W07,一个珍珠膏,一个Moria遮瑕液,一个HPF清洁泥膜。 https://t.cn/A6xesIJb

In December 1883, Monet and Renoir traveled
along the Mediterranean coast. Soon after, Monet made plans to return--this time alone. ("I have always worked better in solitude, and from my own impressions, so keep this secret, until I tell you otherwise," he wrote to his dealer.) His solo travel, in the winter and spring of 1884, resulted in several new works.


发布     👍 0 举报 写留言 🖊   
✋热门推荐
  • 岁月不欺,你一定得到的比失去的更多。所以能疯狂的爱,爱过,说实话,真是幸运的幸运,何其可贵,因为你曾见过自己闪着波澜壮阔的爱之光芒!
  • 这5个方法让孩子爱上水杯】奶瓶的使用在育儿生活中是个充满争议的话题,大家比较关心的就是下面这些问题:长时间使用奶瓶到底有什么危害?没办法,我从小就好喜欢金毛,即
  • 有些人我没说是因为我以为我跟人家是一条心,实际上真是纯纯自作多情,个人管好个人的事吧,反正就这样子了,好不了也坏不了啥。有些人我没说是因为我不希望在他心里我过得
  • 具有柔软心的人,即使面对的是草木,也能将心比心,也能与草木至诚地相见。其实不然,柔软心是道元禅师本具的,甚至是人人本具的,只是,道元若不经过万里波涛,不到中国求
  • #广西天气# #春运天气# 【广西的朋友们今天防雨防寒保暖工作请继续 】冰冻黄色预警和低温蓝色预警 今天白天,桂林、柳州、梧州、玉林、北海等市阴天有小雨,我区其
  • 【新春走基层|无人配送新鲜到家 新业态生鲜超市的独特购物体验】2月18日,由2022北京新闻中心主办的“双奥之城新气象—2022中外媒体北京行”城市形象特色采访
  • #Yui's Diary# ‍ 5⃣️6⃣️ 国庆假期的一些片段 ‍ 5⃣️7⃣️ 假期回来之后累累的 感觉睡不醒哦 每天都困困的 心情也不太好 ‍
  • 于是:————刚刚15:20——我的高铁进站西安北“列车已经到达西安北站,旅客朋友们您旅途辛苦了”;同时,小Z的高铁驶出西安“车门即将关闭,请您注意安全”。还好
  • 一煤独大的经济增长是有非常大的隐忧。煤炭,预计还有10年左右的黄金期,在其期间如果转型不成功,可能就会是玉门鹤岗的梦魇。
  • 嫌乐高贵的可以先试试这个 拼好了摆在桌面看着心情也好,而且还賊有成就感,像我平时压力啥的,就啥也不想一心拼好也很解压! 嫌乐高贵的可以先试试这个 拼好了摆
  • 。啊这就是时光倒流吗!
  • 希望你打球的每一天都是快乐的 就像你说的那样:聚沙成塔 永远做最纯粹的竞争者! 希望你的25岁可以继续闪耀 希望你永远自由自在 健康涨球 做自己最爱的事情 看
  • 这一点非常重要,很多时候利好已经被充分反映,结果就是利好见光死;第四步:决定用多少钱去为这一次决策错误买单;第五步:以愿意承担的亏损去反推应该配置多少仓位;第六
  • #好物分享#领英iOS版持续监视用户由于苹果在 iOS 14 系统更新中引入了一项新的隐私功能,能使 App 在监听用户剪贴板时弹出提示,由此揭露了很多行为不规
  • 保持一颗善良的心,就是人生幸福的源泉,就是一席永恒的筵席,就是被人尊重的资本。积极乐观、不畏困难、勇于突破自我,每个追赶幸福的奋斗者,都是人生的赢家。
  • [鲜花][鲜花]❤️2022.02.22【心语道早安】 ﹊﹊﹊﹊﹊走进幸福,走进美好。❥⇢good morning…华哥早安!
  • 美国20家金属3D打印机厂商大盘点
  • 不清楚的都可以来问我#整形# 深圳全肋鼻+垫下巴,越早美丽越开心我的鼻子我一直是不太满意的,还有下巴我自己觉得有些后缩有点短纠结了很久 到底要不要do个鼻子和
  • 子供の小さな手にキスして、あなたを愛して、愛する人の頬にキスして、あなたを愛して。 ――盧思浩は彼が誇りに思っていたものはすべてゴミの山になった。
  • ”之前有小伙伴投稿,问过大家对18岁发生性关系的看法,评论区收到了很多不同的声音。另外,后台私信也经常会收到很多小姐妹的困惑,不知道什么年龄开始自嗨会比较合适,