Whenever I open a file to edit using my SD card writer, it changes the answer of a previous variable.
String str = "";
char c;
boolean contd = true;
String fileStringMaster;
while (contd == true) {
Serial.println("gonna go again");
fileStringMaster = getMasterData();
if(fileStringMaster != "again") {
break;
}
}
Serial.print("the master string is "); Serial.println(fileStringMaster);
Serial.println();
for (int i = 0; i < fileStringMaster.length(); ++i) {
c = fileStringMaster[i];
if (c == ',') {
Serial.println(str);
str = "";
} else {
str += c;
}
}
This code gets the answers
the master string is 238.00methane,29.00alcohol,25.94temp,48.33humid,417.00CO2 enviro,2.00TVOC,100779.25Pressure,47.09Altitude
238.00methane
29.00alcohol
25.94temp
48.33humid
417.00CO2 enviro
2.00TVOC
100779.25Pressure
47.09Altitude
String str = "";
char c;
boolean contd = true;
String fileStringMaster;
while (contd == true) {
Serial.println("gonna go again");
fileStringMaster = getMasterData();
if(fileStringMaster != "again") {
break;
}
}
Serial.print("the master is "); Serial.println(fileStringMaster);
myFile = SD.open(file_name, FILE_WRITE);
if (myFile) {
Serial.println("start second print");
for (int i = 0; i < fileStringMaster.length(); ++i) {
c = fileStringMaster[i];
if (c == ',') {
Serial.println(str);
myFile.println(str);
str = "";
} else {
str += c;
}
}
myFile.close();
Serial.println("finish second print");
} else {
Serial.println("Did NOT print 2nd time");
}
But, when all I change is that I open a file, I get the answer
the master is
(my function returns nothing. also, the file does not open even though it's formatted to FAT, the file name is less than 8 characters long, and then pins are hooked up correctly)
The function getMasterData() does not change at all between the two code examples.
Does opening a file affect strings in a way that I'm not aware of?
Hopefully some coding wizard out there could explain.
Thanks,
Nathan