sprintf returns ?

I am attempting to read in data from the analog temperature sensor and then display it on the tft touchscreen. Here is a snip of the relevant code:

 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 sprintf(temperature, "%f", temperatureF);
 tft.drawString(40, 100, temperature, GREEN, 4);  // DISPLAY THE TEXT

Unfortunately, the screen simply display a ? ( question mark ). Am I missing something?

Am I missing something?

The ability to search, perhaps.

The %f format specifier is not supported on the Arduino.

PaulS: The ability to search, perhaps.

The %f format specifier is not supported on the Arduino.

Doh!? Obviously I am new to this. :-)

I can't seem to find much documentation of the sprintf function on the Arduino...

I figured it out. This code works:

 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 
 char temperature[10];
 dtostrf(temperatureF,4,1,temperature);
 tft.fillRect(159, 100, 100, 40, BLACK);
 tft.drawString(159, 100, temperature, GREEN, 4);  // DISPLAY THE TEXT

I can't seem to find much documentation of the sprintf function on the Arduino...

. That's because it is not on the reference page, because it is not specific to the Arduino. It should be mentioned, because it is available, but it is not as complete as the PC version.

You can easily create two integers from the temperature, one being the whole part and the other being the fractional part multiplied by some factor of 10. Then, sprintf those two ints, instead of the float.

int wholePart = temperatureF;
int fractPart = (temperatureF - wholePart) * 10;
sprintf(temperature, "%d.%d", wholePart, fractPart);

You could change the 10 to 100, and the second %d to %02d to get two decimal places, but the thermometer you are using probably isn't accurate to even one decimal place.