作者:newbigstart | 来源:互联网 | 2023-10-15 11:24
Ivecreatedavariable-sizedarray(VLA)andIwanttofillitwithusingfgetsfunctionsinafor
I've created a variable-sized array (VLA) and I want to fill it with using fgets
functions in a for
loop. However program passes the some functions and it strangely ignores the first fgets
action.
我已经创建了一个可变大小的数组(VLA),我想在for循环中使用fgets函数来填充它。但是程序传递了一些函数,它奇怪地忽略了第一个fgets动作。
My code is;
我的代码是;
void editorMain(void)
{
printf("Please enter the number of items: ");
scanf("%u", &itemQuantity);
printf("\n\n");
char itemNames[itemQuantity][ITEM_NAME_LEN+1];
memset(&itemNames, 0, sizeof(itemNames));
printf("Please enter the names of items: \n");
char line[ITEM_NAME_LEN+1];
memset(&line, 0, sizeof(line));
for (int i = 0; i = 0; --a) {
if (line[a] == '\n') {
line[a] = 0;
}
else;
}
snprintf(itemNames[i], ITEM_NAME_LEN+1, "%s", line);
}
...
}
And it outputs;
它输出;
Please make a choice: 2
Please enter the number of items: 4
Please enter the names of items:
#1: #2: Marlboro
#3: Parliament
#4: Winston
Please enter the prices of items:
#1: 25
#2: 950
#3: 1000
#4: 800
................... AVAILABLE ITEMS oo
# Item Name Price
= ========= =======
1. 0.25 TL
2. Marlboro 9.50 TL
3. Parliament 10.00 TL
4. Winston 8.00 TL
Enter your item selection:
What's your suggestion?
你的建议是什么?
1 个解决方案