how copy contents of a text file to variable? Help me please!!

My friends who can help thanks.

Must pass the contents of a text file that is in the Arduino sd to a variable .

For example:

the text file has the following names :

Will be just these four names, neither more nor less .

Jack
David
Rose
Steve

then I would have 4 variables :.

variable a = Jack
variable b = David
variable c = Rose
variable d = Steve

How to ?

Help me please!!

Have you looked at any of the SD examples?

I not found an example for this :confused:

Really?

in the example above , failed to send text to a variable...
I need the text in the variable for handle

the text file has the following names :

Will be just these four names, neither more nor less .

Jack
David
Rose
Steve

If that's all the file contains, why bother?
Just copy the strings to string variables. Job done.

You could make a small example ?

You will need the SdFat library in this link.

Here are two example:

readFile()
readDirectory()

See the comments to see where you get the Directory Entry Name and the File Line as string.

#include <SPI.h>
#include <SdFat.h>

#define DIRECTORY_ENTRY_LENGTH  30
#define FILE_LINE_LENGTH        30

SdFat SD;             //Main SD Object

void setup() {
  Serial.begin(115200);
  
  if(!SD.begin(SS)){  //Initialize the SD card using SPI pins + ChipSelect pin
    Serial.println(" Error initializing SD Card ");
    return;
  }
  
  readDirectory("/");       //Read root directory
  readFile("/","Test.txt"); //Read file in Root directory
}

void loop() {
  /* NOTHING */
}

void readDirectory(char* Path){
  Serial.print(F(" -- Reading entries from path = "));
  Serial.println(Path);
  SdFile directory;   //SD Object
  
  char EntryName[DIRECTORY_ENTRY_LENGTH];
  memset(EntryName,0,sizeof(EntryName));
  
  if(SD.chdir(Path)){
    while(directory.openNext(SD.vwd(), O_READ)){
      directory.getName(EntryName,sizeof(EntryName)-1);
      if(directory.isDir())
        strcat(EntryName,"/");

      Serial.print(F(" * "));
      Serial.println(EntryName); //This is where you get one entry name at a time.
      directory.close();
    }
  }
  else
    Serial.println(F("ERROR: Couldn't open path."));

  Serial.println(F("DONE Reading"));
}

void readFile(char* Path, char* FileName){
  Serial.print(F(" -- Reading entries from file = "));
  Serial.print(Path);
  Serial.println(FileName);
  SdFile directory;
  SdFile file;
  
  if(SD.chdir(Path)){
    if(file.open(FileName)){
      
      char Line[FILE_LINE_LENGTH];
      memset(Line,0,sizeof(Line));
      char Char[2];
      memset(Char,0,sizeof(Char));
      
      while (file.available()) {
        Char[0] = file.read();
        if(Char[0]=='\n'){
          Serial.print(F(" * "));
          Serial.println(Line); //This is where you get one line of file at a time.
          memset(Line,0,sizeof(Line));
        }
        else if(Char[0]>=32)
          strcat(Line,Char);
      }
      file.close();
    }
    else
      Serial.println(F("ERROR: Couldn't open file."));
      
    directory.close();
  }
  else
    Serial.println(F("ERROR: Couldn't open path."));

  Serial.println(F("DONE Reading"));
}

Thank you all