Hi,
Using the latest version of IDE (1.6.8 ) with Arduino Due I seem not to be able to use the dtostrf function from stdlib.h. Have seen several topics with dtostrf but was not able to solve this in my code with the answers given. The code is brought back to the bare minimum.
#include <stdlib.h>
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Starting");
char* str = new char[30];
double flt = 2.4567F;
sprintf(str, "%.1f", flt );
Serial.println(str);
dtostrf(flt,2,1,str);
Serial.println(str);
}
Compiling results in error: "'dtostrf' was not declared in this scope".
When the line with dtostrf is commented out, compiling ends successfully, showing I might use sprintf as well, but it just annoys me.
Say what??? What "buffer"? Where is he allocating anything on the heap, or anything that requires freeing? the only "buffer" he has is a character array, which is a stack-based automatic variable.
RayLivingston:
Say what??? What "buffer"? Where is he allocating anything on the heap, or anything that requires freeing? the only "buffer" he has is a character array, which is a stack-based automatic variable.
He is doing it here:
char* str = new char[30];
This reads "allocate me 30 bytes of heap, and put a pointer to that 30 bytes in str". If there is 3k of heap, his chip will jam shut no later than 100 loops() after it is started. Probably sooner.
This reads "allocate me 30 bytes of heap, and put a pointer to that 30 bytes in str". If there is 3k of heap, his chip will jam shut no later than 100 loops() after it is started. Probably sooner.