c - 如何从 C 中具有多个参数的函数调用单个参数?

标签 c

假设您有一个这样的函数:

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/

相关文章:

android - strerror(errno) 调用 read() 和 write() 时返回 "Invalid argument"

c - 如何在 Windows 中复制 system() 命令获取的文本文件的内容?

c# - 如何在运行时编译 C 代码并使用它的函数

带有数据文件的 Python C 扩展

c - 解密时在 AES_encrypt 函数中指定输入字符串长度

ios - 我如何在 Rubymotion 中编写此 C 代码?

c - 在 C 中找到 10,000,000 以内的平方

c - xGEHRD 和 xHSEQR 例程中 WORK 数组的维数在特征值计算中是否应该相等?

C 编程中无法获得正确的输入

c - Queue中的node_add,只插入前3个作为前中后