What is an unsigned char pointer and how is it different from a char pointer in C?
Not much information on unsigned char pointer in C , and How to print the data pointed by an unsigned char pointer?
Any explanation on this will be helpful.
What is an unsigned char pointer and how is it different from a char pointer in C?
Not much information on unsigned char pointer in C , and How to print the data pointed by an unsigned char pointer?
Any explanation on this will be helpful.
Assuming you have something like
unsigned char *p = something;
then
printf( “p = %p\n”, (void *)p );
prints the value of the pointer itself, while
printf( “*p = %hhu\n”, *p );
prints the value of what p
points to as a decimal integer (unsigned).
the documentation is here: https://linux.die.net/man/3/printf
unsigned char x = 0x4d;
unsigned char *y = &x;
printf("pointer: %p, %hhu\n", (void *)y, *y);
endianess do not matter as sizeof(unsgined char)
id always 1.
If you want to pun types via pointers - it is generally a bad idea.
How to print the data pointed to by an unsigned char* p
?
That depends entirely on the datas format. And what you want actually have and what you need.
Is it just a binary blob of known length?
You probably want a hexdump then. Search for it, while it is common, it is not builtin, and there are many options.
Is it really a null terminated string?
Print it using %s
after casting to char*
.
Is it just a single unsigned char
?
Print it using %hhu
after dereferencing.
There is really insufficient information to judge what is needed.