How many files are on the SD card? What are their names?
Their names are the crap printed before "Filenames:"
What is the type for allFilenames?
char **allFilenames = NULL;
What is in actFilename after this?
The crap.
Let's make this simpler. Do NOT try to strip off the .wav from the end of the name. Do NOT implement your own copy method.
I have tried that. It only works with a cast:
strcpy(actFilename, (char*)dirBuf.name);
otherwise the compiler says "invalid conversion from 'uint8_t*' to 'const char*'"
int fileCount = 0;
while(root.readDir(dirBuf) > 0) {
fileCount++;
}
root.rewind();
allFilenames = (char**) malloc(fileCount * sizeof(char*));
int actFile = 0;
while(root.readDir(dirBuf) > 0) {
char actFilename[24];
strcpy(actFilename, dirBuf.name);
allFilenames[actFile++] = strdup(actFilename);
Serial.print("actFilename: [");
Serial.print(actFilename);
Serial.println("]");
}
root.rewind();
Serial.print("Filecount: ");
Serial.println(fileCount);
Serial.println("Filenames:");
for(int i=0;i < fileCount;i++) {
Serial.print(allFilenames[i]);
Serial.println("");
}
Output:
actFilename: [DLDL WAV ]
actFilename: [DRDR WAV ]
actFilename: [LARB WAV ]
actFilename: [LRAB WAV ]
actFilename: [LURBRUD WAV ]
actFilename: [ABABUDU WAV OòñBD]
actFilename: [UUDU WAV ]
actFilename: [START WAV 0a=ñBD]
actFilename: [RRIAB WAV ]
actFilename: [BARLU WAV _®AéBD]
actFilename: [UABBAD WAV ]
actFilename: [BURADLAAWAV 7AéBD]
actFilename: [DUD WAV mAéBD]
actFilename: [UUDLL WAV ]
actFilename: [UB WAV ]
actFilename: [ADLRBDUUWAV ½dóBD]
actFilename: [UDLR WAV ]
actFilename: [UUDD WAV ]
actFilename: [UUUAAAD WAV ]
actFilename: [JOYSTICKWAV ??óBD]
actFilename: [6 WAV ]
actFilename: [7 WAV ]
actFilename: [8 WAV ]
actFilename: [9 WAV]
actFilename: [ERROR WAV ]
actFilename: [1 WAV]
actFilename: [2 WAV]
actFilename: [3 WAV]
actFilename: [4 WAV]
actFilename: [5 WAV]
actFilename: [LLBABU WAV ¡lDD]
actFilename: [WINAMP~1DAT ]
actFilename: [WINAMP~1IDX ]
actFilename: [PMP_USB INI '¦lDD]
Filecount: 34
Filenames:
DLDL WAV
...33 or so empty lines...
don't know how the winamp-files got there, but they would have been filtered... Where the weird signs come from beats me, but I would have ignored them since they are after the 'W' of 'WAV'. As I wrote, the dot does not appear in dirBuf.