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