#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>
struct Cate
{
int No;
char Name[30];
struct Cate *next;
}ca;
int main(){
struct Cate ca[1000]= (struct Cate*)malloc(sizeof(struct Cate)*1000);
ca[0].No=1;
strcpy(ca[0].Name,"Starter");
ca[1].No=2;
strcpy(ca[1].Name,"Barbecues");
ca[2].No=3;
strcpy(ca[2].Name,"Curries");
char str[100]={0};
GATE:
printf("Input:");//输入新的str 把它作为新的元素插入结构体中变成ca[4]
scanf("%s",str);
int i=3;
strcpy(ca[i+1].Name,str);//因为可能继续插入,所以用了一个i
printf("%s\n",ca[i+1]);
int n;
printf("Enter n:");//如果n等于1,就返回继续输入
scanf("%d",&n);
int j=0;
if(n==1)
{
i++;
goto GATE;
}
else//如果n不等于1,就把所有的结构体元素输出
{
for(j=0;j<i;j++)
{
printf("%d\t%s\n",ca[j].No,ca[j].Name);
}
}
return 0;
}
Cate *ca 用malloc
Cate ca[1000]是个Cate数组