Another read text filed from SD card thread...

hi..

finally home from work.. and giving this a shot..

I think Im missing a few of the 'bigger pieces' on how (generally) this is to be handled.. (sorry)..

it seems you have to read in the text file byte by byte (individual characters).....

(similar to serial stuff, from what I have read)

I got this snippet of code from fat16lib author (since I am trying to add this into a hacked up version of WaveHC demo sketch)..

on reading the text file..

//parse data in text file on SD card
  if (!params.open(root, "defaults.txt")) {
    // handle open failure here   
    putstring_nl("open SAMPLE.TXT");
  }
  // read and print file to serial port
  uint8_t c;
  while(params.read(&c, 1) == 1) {
    Serial.print(c);
    //delay(250);
  }
  params.close();

works fine as far outputting it to the serial monitor..

safety=0
maxAmmo=10
mColor=b
aColor=r

is what I see.. and also what I have in the text file..

I had to throw in a temp delay() to test that the data does in fact come over 1 by 1.

because of this.. am I correct on thinking I need to first split the data up by line first (ie: using the carriage return character... is that /r or /n ??)

and THEN do a string compare?

would this be the correct/acceptable approach for this:

create a 'temp' var to hold the individual string data that is coming over.. keep += the next byte/character to this temp var.. until I read a carriage return..

when I reach/encounter a carriage return, dump this temp var I just collected/created to an Array...

clear/empty temp var.. start collecting characters/bytes for the next 'name/value' pair all over again.. until next carriage return is found.. rinse, repeat, until I somehow check for end of file? or more so.. no more data? (there is only 4 lines.. I can even hard code a something for only 4 lines perhaps?)

the C/C+ route confuses me with all the byte talk and very 'low level' (to me) handling we need to do..

I am used to doing:

var someArray:Array = new Array("whatever", "string", "here");

or even mixed data:
var someArray:Array = new Array("whatever", 6, "here");

or even objects inside of the arrays:

var someArray:Array = new Array({name:value, eyes:green}, {name:value2, eyes:blue});

never having to define lengths.. (just as read only attribute to get array length..etc)

or just pushing/popping data into/out of the stack..etc

someArray.push("whatever");

someArray[4] = "new string in index 4 of the array, not 4 characters/bytes";

So any guidance on ditching my old habits for a CLEAR understanding of how to dynamically create/populate arrays..etc..
Do you always have to be sorta 'generous' in your array 'size' to cover anything you MIGHT add to it?

maybe my approach is wrong or over thought?

I tried to check each character as it comes over:

but am getting am error that says:

ISO C++ forbids comparring a pointer to an integer..etc.

//parse data in text file on SD card
  if (!params.open(root, "defaults.txt")) {
    // handle open failure here   
    putstring_nl("open SAMPLE.TXT");
  }
  // read and print file to serial port
  uint8_t c;
  while(params.read(&c, 1) == 1) {
    if(c != "\n"){
      Serial.print(c);
    }else{
      delay(1000);
    }
  }
  params.close();

(seems to be easier if the string is declared in the sketch already!) lol

thanks PaulS.