Convert from uint8_t * to char * in C

skyleguy picture skyleguy · Mar 22, 2017 · Viewed 44.1k times · Source

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 be 0x207. I can see that the value of stackHolder is 0x207 using the debugger. I have a function that takes a char * and prints that. So my question is how can I convert the uint8_t * stackHolder into a char * so I can pass it to my print function?

Answer

emlai picture emlai · Mar 22, 2017

How can I convert the uint8_t * stackHolder into a char *?

By casting:

print((char*) stackHolder);