So I just updated from IDE 0018 to 0022. Oddly enough, one of the programs I wrote before won't compile any longer. It's not a library issue, as I made sure the same libraries were available. The code I wrote is
*/
const char* Sbuilder(){
char dig1= client.read(); //Read in 6 characters as separate variables
char dig2= client.read();
char dig3= client.read();
char dig4=client.read();
char dig5=client.read();
char dig6=client.read();
if(dig4=='.'){ //if it is a three digit number
sprintf(val, "%c%c%c%c%c%c", dig1,dig2,dig3,dig4,dig5,dig6);
}else if(dig3=='.'){ //if it is a two digit number
sprintf(val, "%c%c%c%c%c",dig1,dig2,dig3,dig4,dig5);
}else if(dig2=='.'){ //if it is a one digit number
sprintf(val, "%c%c%c%c",dig1,dig2,dig3,dig4);
}
}
It's a function in the script that is meant to take the characters read from an HTML page and build a string called "val". I get an error claiming "error: cannot convert 'String' to 'const char*' for argument '1' to 'double atof(const char*)".
For reference, the string I build is really numerical value that is later converted. Any ideas why it won't work in the newer version? Or, even a more elegant solution to my code?
We'll need to see more of yours to see what's wrong, but I doubt it is a problem with the compiler.
The error you quote mentions atof() which is not in the fragment of code you've shown. I'm not sure what makes you say it has something to do with sprintf().
Thanks for the replies, I forgot to get email notifications set up.
Nick: "val" is declared as a string. The decimals aren't thrown out, just used as a marker to determine the size of the number that is being accounted for. Other parts of the program treat if differently if it's 10, 100, or 1000.
gardner: That would work, but again, "val" is declared as a string.
Essentially what happens is that an HTML page is read in to build the string "val" which then has to be converted to a float, double, long, or whatever number type to be used by other parts of the program. I can still compile and upload it using 0018, I'm just trying to find the difference in 0022 that would prevent this.
The string class may possibly have had an operator char * declared like this:
operator char *() const { return _buffer; }
That would have cast the internal buffer into char *, allowing you to use it in sprintf. However this is very unsafe to do, as the internal buffer is dynamically allocated and may be the wrong size.
I note the current code is better (it has const char *) but it is commented out: