How to find the length of unsigned char* in C

cchar

I have a variable

unsigned char* data = MyFunction();

how to find the length of data?

Best Answer

You will have to pass the length of the data back from MyFunction. Also, make sure you know who allocates the memory and who has to deallocate it. There are various patterns for this. Quite often I have seen:

int MyFunction(unsigned char* data, size_t* datalen)

You then allocate data and pass datalen in. The result (int) should then indicate if your buffer (data) was long enough...