I'm trying to skip string and parse two values as in code below:
int main()
{
char format[] = "%*s HEX_DATA:%04x, NEGATIVE_VAL:%d";
char str[] = "text_to_be_skipped, HEX_DATA:d800, NEGATIVE_VAL:-20";
uint16_t hex_data = 0;
int8_t neg_val = 0;
int status = sscanf(str, format, &hex_data, &neg_val);
printf("Status: %d, HEX_DATA: %04x, NEGATIVE_VAL: %d", status, hex_data, neg_val);
return 0;
}
It returns the following output:
Status: 2, HEX_DATA: ffff, NEGATIVE_VAL: -20
The hex value is wrong. When , in format[] is removed then output is as follows:
Status: 1, HEX_DATA: d800, NEGATIVE_VAL: 0
Now hex_data value is parsed correctly but neg_val is not parsed. How to parse them all?