简体   繁体   English

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

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

Okay so i wanted to know how would i be able to bind an char type of array called ItemPrefixes to another type of array.好的,所以我想知道如何将名为 ItemPrefixes 的 char 类型的数组绑定到另一种类型的数组。 to provide more clarification提供更多说明

i have to create this fruit portal with the use of both functions and arrays.我必须使用这两个函数和 arrays 创建这个水果门户。 I have declared both arrays as char itemPrefixes[] and int ItemPrices[].我已将 arrays 声明为 char itemPrefixes[] 和 int ItemPrices[]。 the shopkeeper will be asked later on about the item prefixes eg 'A' = apple and the price for the apple being £2.稍后将询问店主有关商品前缀的信息,例如“A”=苹果,苹果的价格为 2 英镑。 However, i have to first bind the position 'i' in ItemPrefixes and itemPrices arrays to a particular item along with its price.但是,我必须首先将 ItemPrefixes 和 itemPrices arrays 中的 position 'i' 及其价格绑定到特定项目。 eg itemPrefixes[0] = 'A' is binded with itemPrices[0] = 2.例如 itemPrefixes[0] = 'A' 与 itemPrices[0] = 2 绑定。

you can try to use struct :您可以尝试使用struct

struct item {
   char name_item;
   int price;
};

then you can create an array of struct然后你可以创建一个结构数组

struct item my_array[10];

you can access the members in this way:您可以通过以下方式访问成员:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM