#include #include #include #include void __assert_func(const char *file, int line, const char *func, const char *expr) { printf("%s:%d (%s) assertion failed: %s\n", file, line, func, expr); exit(1); } int main(void) { uint8_t i2c_addr = 1; uint16_t mem_addr = 1; uint8_t len = 1; int ret; printf("%d, %d, %d\n", i2c_addr, mem_addr, len); //prints: 1,1,1 const char *cmd = "1 2 3\n"; // This is the order I intended to scan the string in ret = sscanf(cmd, "%hhu %hu %hhu", &i2c_addr, &mem_addr, &len); printf("%d- %d, %d, %d\n", ret, i2c_addr, mem_addr, len); assert(i2c_addr ==1 && mem_addr == 2 && len == 3); // prints: 3- 1,0,3 // I just swap the order of the target variables around ret = sscanf(cmd, "%hhu %hhu %hu", &i2c_addr, &len, &mem_addr); printf("%d- %d, %d, %d\n", ret, i2c_addr, len, mem_addr); assert(i2c_addr ==1 && len == 2 && mem_addr == 3); // prints: 3- 1,2,3 return 0; }