Convert from uint8_t * to char * in C
Solution 1
How can I convert the
uint8_t * stackHolder
into achar *
?
By casting:
print((char*) stackHolder);
Solution 2
I have a method that takes a char *
Suggest minimizing casts to one location to accomplish the goal and retain function signature type checking. Create a wrapper function with a cast.
// OP's original function
extern void skyleguy_Print(char *);
void skyleguy_Print_u8(uint8_t *s) {
skyleguy_Print((char *) s);
}
skyleguy
Updated on October 18, 2020Comments
-
skyleguy over 3 years
I am programming in C using Atmel Studio (for those unfamiliar with this it is used to program to micro controllers such as arduino. You can not simply print, you have to send the data Serially to an application such as Terminal.)
I have so far:
uint8_t * stackHolder; char buffer[128]; stackHolder = &buffer[127];
Lets say that the address of
buffer[127]
happens to be0x207
. I can see that the value ofstackHolder
is0x207
using the debugger. I have a function that takes achar *
and prints that. So my question is how can I convert theuint8_t * stackHolder
into achar *
so I can pass it to my print function?