%d
incorrect because it means that you are passing int *
, but you really want to pass uint8_t *
. You will need to use the appropriate macro:
#include <inttypes.h>
...
sscanf(foo, "%2" SCNu8 " %2" SCNu8, &d1, &d2);
Most compilers should give you warnings about your version of the code. Here is the Clang output:
test2.c: 8: 24: warning: format specifies type 'int *' but the argument has type
'uint8_t *' (aka 'unsigned char *') [-Wformat]
sscanf(foo, "%2d %2d", &d1, &d2);
~~~ ^~~
%2s
test2.c:8:29: warning: format specifies type 'int *' but the argument has type
'uint8_t *' (aka 'unsigned char *') [-Wformat]
sscanf(foo, "%2d %2d", &d1, &d2);
~~~ ^~~
%2s
2 warnings generated.
uint8_t
printf()
, uint8_t
int
printf()
.