创建大小可变的数组数组

时间:2018-07-19 06:25:36

标签: arrays arduino

我正在研究一个Arduino项目,该项目需要一个数组数组,每个数组的大小都不同。这是数组:

int seg0[6] = {10, 3, 4, 5, 12, 11};
int seg1[2] = {3, 4};
int seg2[5] = {10, 11, 2, 4, 5};
int seg3[5] = {10, 11, 2, 12, 5};
int seg4[4] = {3, 11, 2, 12};
int seg5[5] = {10, 3, 2, 12, 5};
int seg6[6] = {10, 3, 2, 4, 5, 12};
int seg7[3] = {10, 11, 12};
int seg8[7] = {10, 11, 12, 5, 4, 3, 2};
int seg9[6] = {10, 3, 11, 2, 12, 5};

我想将它们全部放在一个大数组中,以便输入一个数字,例如。 8,然后它将为我提供具有指定索引号的数组({array[0]将给出seg0array[8]将得到seg8,依此类推)。

任何人都有提示吗? 谢谢

1 个答案:

答案 0 :(得分:5)

我猜你在问维数组

int seg0[6] = {10, 3, 4, 5, 12, 11};
int seg1[2] = {3, 4};
int seg2[5] = {10, 11, 2, 4, 5};
int seg3[5] = {10, 11, 2, 12, 5};
int seg4[4] = {3, 11, 2, 12};
int seg5[5] = {10, 3, 2, 12, 5};
int seg6[6] = {10, 3, 2, 4, 5, 12};
int seg7[3] = {10, 11, 12};
int seg8[7] = {10, 11, 12, 5, 4, 3, 2};
int seg9[6] = {10, 3, 11, 2, 12, 5};

// Keep all of seg in a dimension array
int* dimention_array[10] = {seg0, seg1, seg2, seg3, seg4, seg5, seg6, seg7, seg8, seg9};

// Print first element of |seg0|
printf("%d", dimention_array[0][0]);