Reading data from SD CARD .txt file, last byte wrong


hello trying read number sd card .txt file. used function below data last byte wrong. number 2345.
code: [select]

float test = 0.0; //global variable

//inside setup() below

file textdata = sd.open("something.txt");
if(textdata)
{
   while(textdata.available())
   {
     float textread = textdata.read() - '0';
     test = test * 10 + textread;
    }
}


the number 234112.00.
then noticed in .txt file. after 2345 there empty line.
quote
2345
<-- empty line here
when deleted empty line got exact number (2345.00).

does empty line return w/c messed first result?

quote
does empty line return w/c messed first result?
yes; read data , includes carriage return and/or line feed.

solution: read databyte variable, check if it's not '\r' or '\n' , next add test variable (after subtracting '0').



Arduino Forum > Using Arduino > Programming Questions > Reading data from SD CARD .txt file, last byte wrong


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'