&mac[0]
is a pointer to an unsigned char
.1 %hhx
means the corresponding arguments points to an unsigned char
. Use square pegs for square holes: the conversion specifiers in the format string must match the argument types.
1 Actually, &mac[0]
is a pointer to a uint8_t
, and %hhx
is still wrong for uint8_t
. It “works” in many implementations because uint8_t
is the same as unsigned char
in many implementations. But the proper format is "%" SCNx8
, as in:
#include <inttypes.h>
…
scanf(mac_str, "%" SCNx8 "… rest of format string", &mac[0], … rest of arguments);