You can use the sizeof() operator, but that will return the size of the actual pointer. If you are using the unsigned char* to point to a character array, you cannot use sizeof(). You can use strlen(), which counts the number of characters before the terminating '\0' character (which you should make sure is present before using any built-in functions like this), or you can use an extra int parameter and pass in the size when the function is called.