How can I get length of array which is array of unsigned char*
?
This is my array:
unsigned char ot[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0, 0x0, 0x0, 0x0, 0x0 };
I tried to use strlen()
like this:
int length = strlen((char*) ot);
It returns me length of 11 till first 0x0
, but what is my array changes to this? (check last element)
unsigned char ot[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0, 0x0, 0x0, 0x0, 0xa1 };
Then I get still 11 elements, how can I get "real" length of whole array? Like what if there will be data after some 0x0
element.
For example for:
unsigned char* file_buffer = new unsigned char[BUFFER_SIZE];
fread(file_buffer,sizeof(unsigned char),BUFFER_SIZE,input_file)
What could be best solution? Because return value of fread()
can vary, if I am reading last chunk of file, and what if in file will be 0x0
before some data?