假设您有一个这样的函数:
void Inventory(int index, char input[], int qty)
void AddItem(){
int index = Inventory(index);
if (int i = 0; i < index; i++){
...
}
}
但它给了我一个错误““Void”类型的值不能用于初始化“int”类型的实体”
有人可以向我详细解释一下,因为我也是编程新手。
最佳答案
您正在尝试将 index
初始化为 int
,其值是通过调用 Inventory(index)
返回的。但您提供的 Inventory
函数的返回类型为 void
,而不是预期的 int
,因此无法获取该值。
此外,您对 Inventory
的调用缺少 chat input[]
和 int qty
参数的参数。此外,index
在您尝试使用它时尚未初始化(在 index
的定义内)。
关于c - 如何从 C 中具有多个参数的函数调用单个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56096234/