Writing SD card file to a string variable

Hello,

I am trying to read a small file from an SD card to a string variable. I can't seem to figure it out. What do I need to do here? I have no trouble reading to the console as it is but I need read to the variable phoneNumbers.

char phoneNumbers[100];

  phoneNum = SD.open("phoneNum.txt", FILE_READ);
  if (! phoneNum) {
    Serial.println("error opening phoneNum.txt");
    // Wait forever since we cant read data
    while (1) ;
  } 
   if (phoneNum) {
    while (phoneNum.available()) {
      Serial.write(phoneNum.read());
    }
    phoneNum.close();
  }

I want to subsistute phoneNumbers in place of Serial.write so I can parse it.

StanK

This is what I use:

char phoneNumbers[100];
int charPos = 0;
char thisChar;

  phoneNum = SD.open("phoneNum.txt", FILE_READ);
  if (! phoneNum) {
    Serial.println("error opening phoneNum.txt");
    // Wait forever since we cant read data
    while (1) ;
  } 
   if (phoneNum) {
    while (phoneNum.available()) {
      thisChar = phoneNum.read();
      
      if(charPos < 99) {
        phoneNumbers[charPos] = thisChar;
        charPos++;
        phoneNumbers[charPos] = 0;
      }

      Serial.write(thisChar);
    }
    phoneNum.close();
  }

Hello SurferTim,

Thanks for the tip. I should have been able to figure this out. Up too late last night.

StanK