Hi all,
I don't know if I'm just stupid or if what I'm trying to do is not possible, but here's what I need help with:
Consider this array:
const char codes[] = {
{0x00,},
{0x10, 0x11,},
{0x20, 0x21, 0x22,},
{0x30, 0x31, 0x32, 0x33,},
{0x40, 0x41, 0x42, 0x43, 0x44,},
{0x50, 0x51, 0x52, 0x53, 0x54, 0x55,},
{0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,},
};
Now, this line:
[b]uint32_t n = sizeof (codes) / sizeof (*codes)[/b]
;
correctly returns the value "7" telling me that there are seven different "chunks" in the array.
And, I can iterate through them like this:
int main (void)
{
init ();
Serial.begin (115200);
uint32_t x;
uint32_t n = sizeof (codes) / sizeof (*codes);
for (x = 0; x < n; x++) {
fprintf (stdout, "value is 0x%02X\n", codes[x]);
}
while (1);
}
and I get the first byte of each "chunk":
[b]value is 0x00
value is 0x10
value is 0x20
value is 0x30
value is 0x40
value is 0x50
value is 0x60[/b]
What's stumping me is how to get the size of each "chunk". For example, I want "the code" to tell me that the first chunk has one byte, the second one two, etc...
Then I want to be able to access each byte in any order I want. For example, if I did something like this (pseudo code):
[b][tt][tt]print
(codes [3][1]);[/tt][/b]
[/tt]
I would get the second byte of "chunk" 3 which is "0x31".
But I can't seem to figure out how to get the length of each chunk. I can do this:
[b][tt][tt]print
(codes [3] + 1);[/tt][/b]
[/tt]
...and get the "0x31" result, but I have no way of knowing how long "codes[3]" is.
I'm sure I'll kick myself in the behind when I get the answer... it's probably so simple I can't see it.
Any help will, of course, be greatly appreciated. Thanks!
-- Roger