confused beyond belief

Try to write a program that reads setup data from an SD card that is in an Arduino wireless shield on a Mega R3.
Found this code which got me mostly there, and while it reads numbers and bool statements, it wont read the text stirng.
Here is the code; many thanks to Jurgen for getting me this far !

#include <SD.h>
#include <ctype.h>
File myFile;
struct parameters {
  int interval;
  boolean co2;
  boolean temp;
  boolean rh;
  boolean lux;
  boolean valid;
  boolean heater;
  String lokaal;
} settings;
// Setting for SD-card reader
const int chipSelect = 53;
void getSettings()
{
 // Open the settings file for reading:
  myFile = SD.open("settings.txt", FILE_READ);
  char character;
  String description = "";
  String value = "";
  boolean valid = true;
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      character = myFile.read();
             if(character == '/') {
               // Comment - ignore this line
               while(character != '\n'){
                 character = myFile.read();
               };
      } else if(isalnum(character)) { // Add a character to the description
        description.concat(character);
      } else if(character =='=') { // start checking the value for possible results
      // First going to trim out all trailing white spaces
      do {
        character = myFile.read();
      } while(character == ' ');
        if(description == "interval") {
          value = "";
          while(character != '\n') {
            if(isdigit(character)) {
              value.concat(character);
            } else if(character != '\n') {
              // Use of invalid values
              valid = false;
            }
            character = myFile.read();
          };
          if (valid) {
            // Convert string to array of chars
            char charBuf[value.length()+1];
            value.toCharArray(charBuf,value.length()+1);
            // Convert chars to integer
            settings.interval = atoi(charBuf);
          } else {
            // revert to default value for invalid entry in settings
            settings.interval = 60;
          }
        } else if(description == "co2") {
           if (character=='1') {
             settings.co2 = true;
           } else {
             settings.co2 = false;
           }
        } else if(description == "rh") {
           if (character=='1') {
             settings.rh = true;
           } else {
             settings.rh = false;
           }
        } else if(description == "temp") {
           if (character=='1') {
             settings.temp = true;
           } else {
             settings.temp = false;
           }
        } else if(description == "lux") {
           if (character=='1') {
             settings.lux = true;
           } else {
             settings.lux = false;
           }
        } else if(description == "heater") {
          //Serial.println("Heater");
           if (character=='1') {
             settings.heater = true;
           } else {
             settings.heater = false;
           }
        } else if(description == "location") {
          //Serial.println("Location");
          value = "";
           do {
             value.concat(character);
             character = myFile.read();
           } while(character != '\n');
           settings.lokaal = value;
           Serial.print("Location=");
        Serial.println(settings.lokaal);
        }else { // unknown parameter
          while(character != '\n')
          character = myFile.read();
        }
        description = "";
      } else {
        // Ignore this character (could be space, tab, newline, carriage return or something else)
      }
    
    }
    // close the file:
    myFile.close();
}
void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println("Starting...");
  pinMode(53, OUTPUT);
  
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  getSettings();
  Serial.print("Interval: ");
  Serial.println(settings.interval);
  Serial.print("CO2: ");
  if(settings.co2) { Serial.println("YES"); } else { Serial.println("NO"); }
  Serial.print("TEMP:");
  if(settings.temp) { Serial.println("YES"); } else { Serial.println("NO"); }
  Serial.print("RH: ");
  if(settings.rh) { Serial.println("YES"); } else { Serial.println("NO"); }
  Serial.print("lux: ");
  if(settings.lux) { Serial.println("YES"); } else { Serial.println("NO"); }
  Serial.print("htr: ");
  if(settings.heater) { Serial.println("YES"); } else { Serial.println("NO"); }
  Serial.print("Lokaal: ");
  Serial.println(settings.lokaal);
  Serial.println("Done");
  
}
void loop()
{
        // nothing happens after setup
}

Here is the file it is trying to read;

// Any line starting with one forward slash will be considered comment.
// So the typical // will also serve as a comment.

// Measure CO2-level
co2 = 1

// Don't measure relative humidity
rh = 0

// Measure temperature
temp = 1

// Don't measure light strenght
lux = 0

// Location identifier
location = Bathroom

// Don't pre-heat module
heater = 0

// Other parameters are unknown and will be ignored
xrayvision = 1
evilcommand = 0
myname = jurgen

If is change the

 myFile = SD.open("settings.txt", FILE_READ);

to

 myFile = SD.open("settings.txt", FILE_WRITE);

I get all the digits fine, but not the "bathroom" string.
If i change it back to "READ" i get the text but not the digits.

Surely, reading a file is reading a file !
Why should "WRITE" produce results, but only some of them.

Andrew

Opening a file for write shouldn't allow reading at all.

Firstly the code is poorly indented and hard to read - suggest you move all
the parsing code into separate routines, one for reading bool, one for int, one
for string, and write very simple test code for each separately using a simpler
test files and get each working independently first - then reconstruct your
file parser in terms of those routines.

Don't open the file for write if you are going to read it, complete red-herring.

Oh yes, and liberally sprinkle your code with Serial.println() debug statements
so you can see what is really going on, remove only after testing is complete.

               while(character != '\n'){
                 character = myFile.read();
               };

What happens if you encounter the end of the file before you find another carriage return. This becomes an infinite loop.

      } else if(isalnum(character)) { // Add a character to the description

That is NOT what that statement does.

The comment describes the next line, and is obvious to the point of uselessness.

            // Convert string to array of chars
            char charBuf[value.length()+1];
            value.toCharArray(charBuf,value.length()+1);
            // Convert chars to integer
            settings.interval = atoi(charBuf);

You seem opposed to using the String::toInt() function. Why?

          value = "";
           do {
             value.concat(character);
             character = myFile.read();
           } while(character != '\n');
           settings.lokaal = value;
           Serial.print("Location=");
        Serial.println(settings.lokaal);

There are many places where this could go wrong. You need to determine where it went wrong. Is there a typo in the file on the SD card, so that description never actually matches "location"? If not, what does the while loop actually store in value?

Ok, i found this code on the internet and thought it was a good enough place to start, but it now appears to be a poor place to start.

So pointed please so i can start from scratch.
Can i read int, bool and string in the same routine or does it have to be seperate ?

I am new to Arduino so please be gentle.

Andrew

Parsing text-style configuration files like that is not simple. A simple approach leads to a lot of bugs and undetected error handling situations. You need to be very logical and systematic in your approach , and it is not a task for any but the most gifted beginners.

I suggest that you either use Strings systematically, or don't use them at all. On the arduino, the latter is probably preferable.

Can i read int, bool and string in the same routine or does it have to be seperate ?

Yes, you can. You are now, with one probably minor exception. But, that code would be far simpler with some function calls.
Compare

    while (myFile.available()) {
      character = myFile.read();
             if(character == '/') {
               // Comment - ignore this line
               while(character != '\n'){
                 character = myFile.read();
               };
      }

to

    while (myFile.available()) {
      character = skipComment();

Which one is clearer? Which one is likely to be easier to debug?