I'm working on avr microcontroller, and I want to convert a string like "str = 17E388" into an array of char to be as the following: "char arr[3] = {0x17,0xE3,0x88}". any help, please??
I have found the following function. But I don't know how can I call it.
unsigned char *mkBytArray (char *s, int *len) {
unsigned char *ret;
*len = 0;
if (*s == '\0') return NULL;
ret = malloc (strlen (s) / 2);
if (ret == NULL) return NULL;
while (*s != '\0') {
if (*s > '9')
ret[*len] = ((tolower(*s) - 'a') + 10) << 4;
else
ret[*len] = (*s - '0') << 4;
s++;
if (*s > '9')
ret[*len] |= tolower(*s) - 'a' + 10;
else
ret[*len] |= *s - '0';
s++;
*len++;
}
return ret;
}