Here is what I have been experimenting with:
void readFileLine(fs::FS &fs, const char * path) {
File file = SD.open(path);
while (file.available()) {
list = file.readStringUntil('\n');
//Serial.println (list);
recNum++;
for (int i = 0; i < 12; i++) {
if (recNum == (i)) {
Serial.println (i);
Serial.println (list);
delay (1000);
}
}
}
}
To be completely honest, I have no idea what I am doing 
Some background on the project.
Its a datalogger that writes a temperature value to one of 12 GUI text elements, one after another, by pressing a button.
The 12 values can then be saved to an SD card, the values are saved each to a new line.
(everything to this point is working well)
Im currently working on the recall function, trying to write each of the 12 lines back to each of the 12 GUI text elements.
I need to somehow create an SD read function that can be used inside of a for loop
The hypothetical code would allow me to write lines to GUI elements in the following way:
for (int i = 0; i < 11; i++) {
snprintf(logVal, MAX_STR, "%.2f", ReadLine[i]);
gslc_ElemSetTxtStr(&m_gui, (textfield[i]) , logVal);
}
ReadLine would be the contents of the line, and [ i ] the line number/index
Then in the same loop the GUI element to be written to is also updated by [ i ] (I have an array called textfield containing element references)
This means that the first line in the .txt file is written to the first element in the textfield array, and so on, until all 12 elements have been updated with the values from the .txt file.
unfortunately I havent been able to get it working.
Here is a larger portion of my code to help create a picture of whats goin on inside my program.
int counter (-1);
char logTemp[5];
char nullVal[5];
char logName[MAX_STR + 1];
static char nullnullval[7] = "---.--";
int recNum = 0;
String list;
bool CbBtnCommon(void* pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nX, int16_t nY)
{
// Typecast the parameters to match the GUI and element types
gslc_tsGui* pGui = (gslc_tsGui*)(pvGui);
gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
gslc_tsElem* pElem = gslc_GetElemFromRef(pGui, pElemRef);
gslc_tsElemRef* textfield[] = {
DATA_TEXT_1,
DATA_TEXT_2,
DATA_TEXT_3,
DATA_TEXT_4,
DATA_TEXT_5,
DATA_TEXT_6,
DATA_TEXT_7,
DATA_TEXT_8,
DATA_TEXT_9,
DATA_TEXT_10,
DATA_TEXT_11,
DATA_TEXT_12,
};
TS_NTC_103 sensor (0.11, 10);
float Temp (sensor.getTemp(analogRead(36)));
float readLog;
if ( eTouch == GSLC_TOUCH_UP_IN ) {
// From the element's ID we can determine which button was pressed.
switch (pElem->nId) {
case NEXT_DATA_BTN:
counter++;
if (counter > 11) {
counter = 0;
}
snprintf(logTemp, MAX_STR, "%.2f", Temp);
gslc_ElemSetTxtStr(&m_gui, (textfield[counter]) , logTemp);
break;
case PREV_DATA_BTN:
if (counter >= 0)
{
snprintf(nullVal, MAX_STR, "%.2f", nullnullval);
gslc_ElemSetTxtStr(&m_gui, (textfield[counter]) , nullnullval);
counter --;
}
break;
case RESET_DATA_BTN:
gslc_SetPageCur(&m_gui, Log_Delete);
break;
case SAVE_SD_BTN:
gslc_SetPageCur(&m_gui, E_PG_POPUP3);
break;
case LOG_DEL_Y:
for (int i = 0; i < 12; i++) {
snprintf(nullVal, MAX_STR, "%.2f", nullnullval);
gslc_ElemSetTxtStr(&m_gui, (textfield[i]) , nullnullval);
delay (10);
}
counter = -1;
gslc_SetPageCur(&m_gui, E_PG5);
break;
case LOG_DEL_N:
gslc_SetPageCur(&m_gui, E_PG5);
break;
case OPEN_LOG_BTN:
readFileLine(SD, logName);
Serial.println (recNum);
break;
case SAVE_LOG_BTN:
deleteFile(SD, logName);
writeFile (SD, logName, gslc_ElemGetTxtStr(&m_gui, (textfield[0])));
appendFile(SD, logName, "\n");
for (int i = 1; i < 12; i++) {
appendFile(SD, logName, gslc_ElemGetTxtStr(&m_gui, (textfield[i])));
appendFile(SD, logName, "\n");
delay(20);
}
break;
case CLOSE_LOG_PUP:
gslc_SetPageCur(&m_gui, E_PG5);
break;
//<Button Enums !End!>
default:
break;
}
}
return true;
}
bool CbListbox(void* pvGui, void* pvElemRef, int16_t nSelId)
{
gslc_tsGui* pGui = (gslc_tsGui*)(pvGui);
gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
gslc_tsElem* pElem = gslc_GetElemFromRef(pGui, pElemRef);
if (pElemRef == NULL) {
return false;
}
// From the element's ID we can determine which listbox was active.
switch (pElem->nId) {
//<Listbox Enums !Start!>
case E_ELEM_LISTBOX1:
if (nSelId != XLISTBOX_SEL_NONE) {
gslc_ElemXListboxGetItem(&m_gui, pElemRef, nSelId, logName, MAX_STR);
}
break;
//<Listbox Enums !End!>
default:
break;
}
return true;
}
void readFileLine(fs::FS &fs, const char * path) {
File file = SD.open(path);
while (file.available()) {
list = file.readStringUntil('\n');
//Serial.println (list);
recNum++;
for (int i = 0; i < 12; i++) {
if (recNum == (i)) {
Serial.println (i);
Serial.println (list);
delay (1000);
}
}
}
}
void writeFile(fs::FS &fs, const char * path, const char * message) {
File file = fs.open(path, FILE_WRITE);
file.print(message);
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message) {
File file = fs.open(path, FILE_APPEND);
file.print(message);
file.close();
}
void deleteFile(fs::FS &fs, const char * path) {
fs.remove(path);
}
void readFile(fs::FS &fs, const char * path) {
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while (file.available()) {
Serial.write(file.read());
}
file.close();
}