Вопрос

I want to access certain data which basically looks like this:

char* a[]={
    "0000000000",
    "0000000000",
    "0011111100",
    "0000100100",
    "0000100100",
    "0011111100",
    "0000000000",
    "0000000000",
};

I have around 200 of those data sets and want to access it in the way.

fooBar[23]; --> This should return the 23rd character array (which looks like the example listed above).

As far as I understand from my other programming knowledge, I would need an array of Strings. The array index is my lookup number (which will be a maximum of 255). The array values are the character arrays as shown above.

How can this be accomplished with C (Arduino IDE)?

Это было полезно?

Решение

Just use a two dimensional array. Like:

char a[][]={
    "0000000000",
    "0000000000",
    "0011111100",
    "0000100100",
    "0000100100",
    "0011111100",
    "0000000000",
    "0000000000",
};

Другие советы

Based on your comment, I think this is what you are asking for:

const char* data_sets[][200] =
    {
        { "00000", "11111",         },
        { "22222", "33333", "44444" },
        { "55555"                   },
    };

Each entry in data_sets is an array of 200 const char*. For accessing:

for (size_t i = 0; i < sizeof(data_sets) / sizeof(data_sets[0]); i++)
{
    const char** data_set = data_sets[i];
    printf("data_set[%u]\n", i);
    for (size_t j = 0; data_set[j]; j++)
    {
        printf("  [%s]\n", data_set[j]);
    }
}

See online demo at http://ideone.com/6kq2M.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top