views:

54

answers:

2

I'm using this library to convert a float to a string: http://www.arduino.cc/playground/Main/FloatToString?action=sourceblock&ref=1 .

This is the snippet of code, where printing out flt looks like "29.37":

    float flt = tempSensor.getTemperature();
    char buffer[25];
    char str[20];
    Serial.print(floatToString(str, flt, 2, 10));

This should work out of the box, but doesn't - what did I do wring? These are my compile errors:

.../floatToString.h:11: error: expected primary-expression before ',' token
.../floatToString.h: In function 'char* floatToString(char*, float, int, int, bool)':
.../floatToString.h:11: error: default argument missing for parameter 5 of 'char* floatToString(char*, float, int, int, bool)'
.../floatToString.h:73: error: 'itoa' was not declared in this scope
.../floatToString.h:89: error: 'itoa' was not declared in this scope
A: 

default argument missing for parameter 5 of 'char* floatToString(char*, float, int, int, bool)

Looks like you're missing a value: floatToString(str, flt, 2, 10)

Try adding True or False to the end there

Wayne Werner
It has a default value of `false`
jdehaan
Well, then I guess that's what should go in there...
Wayne Werner
A: 

In C++ only all last parameters are allowed to have a default value:

BAD rightjustify MUST have a default value:

char * floatToString(char * outstr, float value, int places,
    int minwidth=0, bool rightjustify) {

OK: no default values, last or two last parameters have default values

char * floatToString(char * outstr, float value, int places,
    int minwidth, bool rightjustify) {

char * floatToString(char * outstr, float value, int places,
    int minwidth, bool rightjustify=false) {

char * floatToString(char * outstr, float value, int places,
    int minwidth=0, bool rightjustify=false) {

Check your header, I guess the one you linked is not the one you currently use.

There is another pointer to an issue: ito is unknown to the compiler. It should be in cstdlib, so an #include <cstdlib> is missing, I would put it in the header, because it depends on it.

jdehaan