2

Here’s the code:

void setup() { Serial.begin(9600); delay(300); double lat = 1111.11; double lon = 4444.44; const byte len{10}; char sLat[len]; char sLon[len]; dtostrf(lat, len, 2, sLat); Serial.println(sLat); Serial.println("---"); dtostrf(lon, len, 2, sLon); Serial.println(sLon); Serial.println(sLat); // <-- prints nothing! Serial.println("---"); dtostrf(lat, len, 2, sLat); Serial.println(sLat); Serial.println(sLon); // <-- prints nothing! } void loop() { } 

Here’s the output:

 1111.11 --- 4444.44 --- 1111.11 4444.44 1111.11 

As you see. Every next call for dtostrf ruins the previous results, in a weird way.

What’s the problem?

1 Answer 1

2

If len is the text array size, you need space there for the terminating '\0'. So the second paramater to dtostrf has to be smaller than len.

1
  • Yeah, of course, your're right! Thanks a lot! I fixed declaration: char sLat[len+1] Commented Oct 24, 2019 at 16:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.