如何在 C 编程中将一个数组绑定到另一个数组?

How can i bind an an array to another array in c programming?

好的,所以我想知道如何将名为 ItemPrefixes 的 char 类型的数组绑定到另一种类型的数组。 提供更多说明

我必须使用函数和数组来创建这个水果门户。 我已将这两个数组声明为 char itemPrefixes[] 和 int ItemPrices[]。稍后将询问店主有关商品前缀的信息,例如 'A' = apple,而苹果的价格为 2 英镑。但是,我必须首先将 ItemPrefixes 和 itemPrices 数组中的位置 'i' 绑定到特定项目及其价格。例如,itemPrefixes[0] = 'A' 与 itemPrices[0] = 2.

绑定

你可以尝试使用struct:

struct item {
   char name_item;
   int price;
};

然后你可以创建一个结构数组

struct item my_array[10];

您可以通过以下方式访问成员:

my_array[index].name_item;
my_array[index].price;