我需要做一些存储记录,我需要能够插入,查看数据并根据ID进行搜索(我还没有到达搜索部分)。我的问题是未记录数据,或者由于索引问题imo无法将它们都打印出来。我该怎么办?
struct item{
char *name;
int qty;
}item [10];
int main ()
{
int i=0,n,menu;
printf("Goody Storage\n");
printf("=============\n");
printf("Input Storage[1..10]: ");
scanf("%d",&n);
for(;;i++){
if(n<=10){
printf("\nGoody Storage\n");
printf("=============\n");
printf("\n1. Add Items\n");
printf("2. See Items\n");
printf("3. Search Items\n");
printf("4. Exit\n");
printf("Choose Menu[1..4]: ");
scanf("%d",&menu);
switch(menu){
case 1 :
printf("Input name of item %d: ", i+1);
scanf("%s",&item[i].name);
printf("Input qty of item %d: ", i+1);
scanf("%d",&item[i].qty);
continue;
case 2 :
printf("\nNo.\tName\t\t\tQuantity\n");
printf("========================================\n");
printf("%d\t%s\t\t\t%d\n", i, item[i].name, item[i].qty);
continue;
/*case 3 :
printf("\nInvalid Choice");
continue;*/
case 4 :
return 0;
default :
printf("\nInvalid Choice");
}
} else break;
}
}