Standard lib Arduino_STD_PRINTF enabled or disabled?

void setup() {
  Serial.begin(115200);

  int val = 0, n = sscanf("123", "%d", &val);
  Serial.println(val);

  String str = String((float) 123);
  Serial.println(str);
}

With standard lib Arduino_STD_PRINTF disabled it prints:

123
_rtl_sprintf: format not support!
.2f

No float-to-string conversion possible.

With standard lib Arduino_STD_PRINTF enabled it prints:

0
123.00

Now sscanf fails.
Is there any setup to get both working?

Hi @Joe, since sscanf is undef when Arduino_STD_PRINTF enabled, and this method parses the string “123” into an integer val, which will then prints the integer value of val. You may just try to print integer straight using:
int val = 123;
Serial.println(val);

Here are another example using atoi to convert string to integer:

const char *input = “123”;
int val = atoi(input); // Avoid sscanf, directly parse integers
Serial.println(val);

Thank you.

Thanks for your answer. However, the code above was only a silly example for demonstration. My real code is of course more challenging:
sscanf(arg, "%d %d %d %d %d %c %f %f", &prog, &lfo, &type, &minVal, &maxVal, &mode, &step, &len);
How would you implement this?
Thanks in advance.

Hi @Joe, after reviewing there was a bug on the std lib for sscanf. We will be fixing it. Thank you for your review.

1 Like

Hi @Joe , the bug on the std lib for sscanf was fixed, you may update to the latest early release for 3.1.8-build20250206 and enable Arduino_STD_PRINTF to test on the sscanf. Thank you.