How to get the number of elements of a byte array

Hi, I have declared a variable type byte array,

uint8_t bufferMSGtoClient[120];

but after this variable is updated with values ​​in the first 10 positions, now I need to get the size of the elements of this variable

When I use sizeof I get the size of the variable which is 120 and not 10 as it should be

int len = sizeof(bufferMSGtoClient)

I have also used

int len = sizeof(bufferMSGtoClient) / sizeof(bufferMSGtoClient[0]);

but the result is the same, can someone tell me how to get the number of elements that this variable has updated

That array has 120 elements, that’s it. It’s size is fixed at 120 elements, regardless of which ones have (or have not) been written to.
If you’ve written to 10 of them you will need to keep track of that in another variable.
There’s no way to get it from sizeof() or using any other code.

Show the other code that writes to the elements.
Say how you can tell if an element is “written”. For example does zero indicate an unwritten variable, or do we need to keep track of that separately?
Also if I just write element 5 (without writing any others first), is that one element written, or 6 (i.e. the index after the highest one used).

Edit: If it’s a character string, and it has a NUL (0) terminator at the end, then you can use the strlen(bufferMSGtoClient) function to count up until the NUL terminator. However you data type should ideally be ‘char’ and not ‘uint8_t’ to indicate this.

OK, understood, Thank you!