问题遇到的现象和发生背景
用代码实现输入菜谱价格就可以跳出对应菜谱
#include<stdio.h>
#include
int main() {
struct caipu
{
char name[200];
double price;
int floor;
int shitang;
}cp[30] = { { "西红柿炒鸡蛋",3.5f,1,1 },
{ "炒茄子", 2.5f, 2, 1 },
{ "蛋炒饭", 6, 1, 2 }};
struct caipu * p;
struct caipu q;
printf("菜名:");
scanf("菜名:",p->name);
for (p = cp; p < cp + 3; p++) {
//ruct caipu* pxcj = &xcj;
printf("价格·%.2lf元\n", p->price);
printf("%d楼\n", p->floor);
printf("%d食堂\n", p->shitang);
}
return 0;
}
我想要达到的结果
我在运行之后发现会将所有菜谱的价格都打印出来,可是我只是想让它打印出对应的菜谱,该怎么修改呢?