1
void loop()
{

  float temperature = dht.readTemperature();
  char test[50];
  sprintf(test, "Temp: %f", temperature);

  Serial.println(temperature); // works fine
  Serial.println(test); // why it prints "?"
  
  delay(300);
}

// Output

24.10   <== Serial.println(temperature);
?       <== Serial.println(test);
24.10
?
24.10
?
24.10
?

Hi. I'm arduino/c newbie. Why print test is keep showing "?" Am I missing something? When I running the below code in c++ playground, it works fine.

float temperature = 23.19;
char test[50];
sprintf(test, "Temp: %f", temperature);
printf("%s", test);        <==== Works fine!
2
  • 2
    I think this article should help sprintf in Arduino Commented Dec 31, 2021 at 21:32
  • 1
    @RohanS Thanks a lot! I will close this article Commented Dec 31, 2021 at 21:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.