I just found a solution that convert a string of mac address to a array like below:
#include <stdio.h>
int main()
{
char mac[] = "ff-13-a9-1f-b0-88";
unsigned char a[6];
sscanf(mac, "%x-%x-%x-%x-%x-%x", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
printf("%x,%x", *a, *(a+1));
}
This piece of code works ok and fits my needs. But what if I want to convert a long string like ff-13-a9-1f-b0-88...(REPEAT 100 TIMES)...-ff-00
to char array?
Repeatedly write %x-%x
in code is neither convenient nor elegant.
I do consider to use memcpy
with a loop, but I just cannot copy half a byte(convert 0x0f, 0x0f to 0xff), right?