I've read that it's best to avoid using String in Arduino so I'm ready to use a char array if it's better. I'm reading the file names from an SD Card and my goal is to store them in an array and then be able to read that array. What I'm currently doing is:
String lib_arr[100];
int lib_arr_size;
and then
File dir = SD.open("/");
int c = 0;
while (true) {
File entry = dir.openNextFile();
if (!entry) {
// If no more files
lib_arr_size = c - 1;
break;
}
if(strcmp(entry.name(), "SYSTEM~1") == 0) {
continue;
}
lib_arr[c] = entry.name();
entry.close();
c++;
}
and then
for (int i = 0; i < lib_arr_size; i++) {
if(i == pos) {
tft.print("> ");
tft.println(lib_arr[i]);
} else {
tft.println(lib_arr[i]);
}
}
This is not a solution because, for my purposes, the String lib_arr[100] can be 1000 or 10000 or 100000... and I found out that by increasing that value the global variables use skyrockets and Arduino says that it's out of memory. My goal is memory optimization. I don't know how to go about this problem.