Reputation: 1281
I'm working on an Arduino project which requires an array of arrays, each with varying sizes. Here are the arrays:
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};
I'd like to have them all in one big array, so that I can enter a number, eg. 8, and then it would give me the array with the index number which was specified (array[0]
would give seg0
, array[8]
would give seg8
, etc).
Anyone have any tips? Thanks
Upvotes: 2
Views: 302
Reputation: 12154
I guess you are asking about dimension array
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]);
Upvotes: 5