📄 qname.c.txt
字号:
/*=======quame.c:按名称查询商品信息记录===============*/
#include "stdio.h"
void QueryByName()
(
int result=0;/*"result=1"说明查询成功,反之查找失败*/
product TmpS;/*定义进行操作时的临时结构体变量*/
char Xingming[20];/*用户输入要查询的商品名称*/
char DateFile[40] = ""、next
/*DateFile存储商品信息的文件名,next为是否进行下一次删除操作的选项*/
FILE *fp=NULL;
/*====fp指针指向存储数据的文件名====*/
/*提示用户输入要查询的文件名*/
printf("\nplease input the name of product information file .\n");
gets(DateFile);
/*提示用户输入要查询的文件名*/
while(*DateFile == ('\0'))
{
printf("\nplease input the name of product information file .\n");
gets(DateFile);
}
/*提示用户输入要查询的文件名*/
begin:
result=0;
printf("please input the name of product which needs look up (under 20 bit figure).\n");
scanf("%s".&Xingming);
getchar();
/*以读方式打开文件*/
pf=fopen (DateFile ."r");
if (fp=NULL)
{
printf("\nOpen file%sfale!Eed with any key .\n".DateFile);
perror(open file fail");
getch();
exit(1);
}
/*循环查找和输入名称相匹配的商品信息记录,如果查找到,则输出结果*/
while(feof(fp==0))
{
if(fread(&TmpS.sizeof(product).1,fp)!=(int)NULL)
(
if (stricmp(Tmps,Name,xingming)==0)
{
printf ("\n Find:)\n");
printf("\nNumber=%ld Name=%s price=%4.if discount=%4.if meberprice=%4.if\n".TmpS.Number.Name.Tmps.price.TmpS.discount.TmpS.memberprice);
result=1;/*"result=1"说明找到了该商品的对应信息.*/
}
}
}
fclose(fp);
/*提示用户已查到结果并询问是否继续查找*/
if (result == 0 )
{
printf("There is no date of this product in the file!")
}
printf("\nGo on ?(y/n)");
next=getche();
putchar('\n');
if (next=='y' || next =='y')goto begin ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -