I have a uint8_t array which should look like this .
uint8_t code[1000] = {0x66, 0xba, 0xf8, 0x03}
Now I cant hard code values in that array instead , I need to insert them one by one from char buffer[300]
. The content of char buffer[300]
is a space delimited string of hex values "66 ba f8 03"
The code I wrote is -
char* token = strtok(buffer, " ");
// Keep printing tokens while one of the
// delimiters present in str[].
int pc = 0;
while (token != NULL) {
code[pc] = token; // This part is wrong. I need to cast it properly
token = strtok(NULL, " ");
pc++;
}
How can I convert a string value into a uint8_t
value?