What is the proper way to initialize unsigned char*
? I am currently doing this:
unsigned char* tempBuffer;
tempBuffer = \"\";
The second method will leave you with a null pointer. Note that you aren't declaring any space for a buffer here, you're declaring a pointer to a buffer that must be created elsewhere. If you initialize it to ""
, that will make the pointer point to a static buffer with exactly one byte—the null terminator. If you want a buffer you can write characters into later, use Fred's array suggestion or something like malloc
.