#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Cate
{
int No;
char Name[30];
};
int main() {
struct Cate ca[10] =
{
{1,"Starter"},
{2,"Curries"},
{3,"Barbecues"}
};
char str[100] = { 0 };
int i = 3;
int n;
do {
printf("Input:");
scanf("%s", str);
strcpy(ca[i].Name, str);
ca[i].No = i + 1;
printf("%s\n", ca[i].Name);
printf("%d\n", ca[i].No);
i++;
printf("Enter n:");
scanf("%d", &n);
} while (n == 1);//当n不等于1时停止插入数据
int j = 0;
for (j = 0; j < i; j++)
{
printf("%d\t%s\n", ca[j].No, ca[j].Name);//显示当前的数据
}
printf("Input:");
int M;
scanf("%d", &M);//输入想删除数据的编号
for(int k=0;k<i;++k)
{
if(ca[k].No=M)
{
ca[k]=ca[k+1];//让下一位数据替换上一位
}
}
for (j = 0; j < i; j++)
{
printf("%d\t%s\n", ca[j].No, ca[j].Name);
}
return 0;
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/47873900004616.png?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)