fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8. char format[] = "%*s HEX_DATA:%4hx, NEGATIVE_VAL:%hhd";
  9. char str[] = "text to be skipped, HEX_DATA:d800, NEGATIVE_VAL:-20";
  10.  
  11. uint16_t hex_data = 0;
  12. int8_t neg_val = 0;
  13.  
  14. int status = sscanf(str, format, &hex_data, &neg_val);
  15.  
  16. printf("Status: %d, HEX_DATA: %04x, NEGATIVE_VAL: %d", status, hex_data, neg_val);
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 4168KB
stdin
Standard input is empty
stdout
Status: 0, HEX_DATA: 0000, NEGATIVE_VAL: 0