Changed it the fixed-sized array:
int fileCount = 0;
while(root.readDir(dirBuf) > 0) {
if(dirBuf.name[0] != 0 && dirBuf.name[0] != 87 && dirBuf.name[0] != 32)
fileCount++;
}
root.rewind();
allFilenames = (char**) malloc(fileCount * sizeof(char*));
int actFile = 0;
while(root.readDir(dirBuf) > 0) {
int actLength = strlen((char*)dirBuf.name);
char actFilename[24] = {
};
if(actLength < 24) {
//copy string until 'W' or space or NULL
int i = 0;
while((char)dirBuf.name[i] != 'W' && (char)dirBuf.name[i] != ' ' && dirBuf.name[i] != 0) {
actFilename[i] = (char)dirBuf.name[i];
i++;
}
if(i>0) {
actFilename[i+1] = 0;
allFilenames[actFile] = strdup(actFilename);
actFile++;
for(int j=0;j<strlen(actFilename);j++)
Serial.print(actFilename[j]);
Serial.println("");
}
}
else {
Serial.println("Filename too long");
}
}
root.rewind();
Serial.println("Filenames:");
for(int i=0;i < fileCount;i++) {
for(int j=0;j < strlen(allFilenames[i]);j++) {
Serial.print(allFilenames[i][j]);
}
Serial.println("");
}
}
This is the Serial Monitor result:
DLDL
DRDR
LARB
LRAB
LURBRUD
ABABUDU
UUDU
START
RRIAB
BARLU
UABBAD
BURADLAA
DUD
UUDLL
UB
ADLRBDUU
UDLR
UUDD
UUUAAAD
JOYSTICK
6
7
8
9
ERROR
1
2
3
4
5
LLBABU
PMP_USB
Filenames:
DLDL
DRDR
LARB
LRAB
LURBRUD
ABABUDU6
(more empty lines until fileCount)
I'm about to give up on this bullsh*t, we both invested already way too much time...