我有一些想要更新的数组。问题是当数据添加到数组中时,一些变量会更新为 0。
我添加数据的代码:
void addStockItem(){
system(CLS_NAME);
printf("New Item\n\n");
printf("New Item Name : ");
fflush(stdin);
scanf(" %[^\n]s",&*itemName[totalItem]);
//itemName[totalItem][30] = strupr(itemName[totalItem]);
fflush(stdin);
printf("New Item Price : ");
scanf("%f",&item_Price_Profit[totalItem][0]);
printf("New Item Profit : ");
scanf("%f",&item_Price_Profit[i][1]);
printf("New Item Qty : ");
scanf("%d",&itemQuantity[totalItem][0]);
itemQuantity[totalItem][1]=0;
itemQuantity[totalItem][2]=0;
++totalItem;
allStocks();
}
数据,
int totalItem=13,itemQuantity[][3]={8,0,0,9,0,0,11,0,0,0,0,0,20,0,0,22,0,\
0,16,0,0,18,0,0,9,0,0,7,0,0,5,0,0,12,0,0,0,0,0},sessionQuantity;
float item_Price_Profit[][2]={1,0.5,2,0.2,3,0.2,4,0.2,5,0.5,6,0.8,7,0.5,8,0.2,9,\
0.2,10,0.2,11,0.5,12,0.8,13,0.9};
char itemName[][30]={"STABILO PENCIL 2B","STABILO PEN 0.5",\
"STABILO ERASER","STABILO RULER","STABILO TEST PAD","STABILO BOOK","STABILO SCISSORS","STABILO SHARPENER","STABILO GLUE","STABILO CHALK","STABILO MARKER PEN","OXFORD DICTIONARY","STABILO HIGHLIGHTER"};
完整代码: http: //pastebin.com/jjuCCrjz
[编辑] 在我将 itemQuantity[][3] 更改为 itemQuantity[100][3]、item_Price_Profit[][2] 更改为 item_Price_Profit[100][2] 和 itemName[][30] 更改为 itemName 之后,一切都按预期工作[100][30]。除了scanf,我还有什么可能犯的错误?