I have an array of pointers to byte arrays of varying length.
How can I determine the length of a given byte array in this scenario?
I guess I could count the array lengths by hand and store them in another array, but that seems like an undue amount of work doing something (counting) that computers excel at automating!
Below code illustrates the problem:
void setup()
{
Serial.begin(9600); // for debugging
byte zero[] = {8, 169, 8, 128, 2,171,145,155,141,177,187,187,2,152,2,8,134,199};
byte one[] = {8, 179, 138, 138, 177 ,2,146, 8, 134, 8, 194,2,1,14,199,7, 145, 8,131, 8,158,8,187,187,191};
byte two[] = {29,7,1,8, 169, 8, 128, 2,171,145,155,141,177,187,187,2,152,2,8,134,199, 2, 2, 8, 179, 138, 138, 177 ,2,146, 8, 134, 8, 194,2,1,14,199,7, 145, 8,131, 8,158,8,187,187,191};
byte* numbers[3] = {zero, one, two };
function(numbers[1], sizeof(numbers[1])/sizeof(byte)); //doesn't work as desired, always passes 2 as the length
function(numbers[1], 25); //this works
}
void loop() {
}
void function( byte arr[], int len )
{
Serial.print("length: ");
Serial.println(len);
for (int i=0; i<len; i++){
Serial.print("array element ");
Serial.print(i);
Serial.print(" has value ");
Serial.println((int)arr[i]);
}
}
Thank you Arduino gurus!