Hi!
This may sound noobie, but I'm stuck on this problem for a few days. I'm trying to store the file names of a directory from an SD card to an array, but no matter what I try, it won't work
I have a global variable for storage:
char *sdfiles[200];
And I have two functions, one to read the file names to the array, and an other one to print them through serial.
void cacheDirectory(File dir) {
int i;
while(true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
//Serial.println("**nomorefiles**");
break;
}
sdfiles[i] = entry.name();
Serial.println(sdfiles[i]);
i++;
}
}
void printSDCache() {
Serial.println("SD cache: ");
for(int i = 0;i <= files;i++) {
Serial.println(sdfiles[i]);
}
}
And this is how i call them form the setup() :
root1 = SD.open("/");
cacheDirectory(root1);
printSDCache();
When I call them from the setup() the cacheDirectory() seems to work, when i print the values back after storing them. But when I call the printSDcache() afterwards, i just get memory garbage I've tried using String array instead of char*, but that hangs my DUE. I've even tried an array of structs, but that gave me the same result as the char* array.
Any help would be appreciated!
Thank you!