I was creating a sketch to run a custom-formatted program from a sd card. I am working on creating, changing and reading variables but when I created the creating function, it printed weird numbers to the sd card. It printed 989711097110974449501310 for some reason. Here is the function:
after the brackets, it runs the setVar() function to change the value. that function does not work so the next reading (the >< after the brackets) are blank
Could this be because varFile.read() returns an int, so d += varFile.read(); will append the hexadecimal decimal representation to the string d? Try doing d += char(varFile.read()); instead to see if that fixes it.
It will append the number in "normal" decimal notation, hence 989711097110974449501310.
The reason read returns a signed int instead of a char (or uint8_t) is for when there is nothing available: it returns -1. So the loop can more obviously express this behavior like
int c;
while ((c = varFile.read()) >= 0) {
d += (char) c;
}
(although that does leave the variable c in scope after the loop)
Calling read() until it returns -1 is my preferred method too. I've long thought that calling available() before read() is redundant since read() already tells you if anything was available.
I used char(varFile.read()); and it read it normal (it said banana,12 instead of 989711097110974449501310) thanks. The setVar() function still doesn't work sadly. I'll keep you updated