Array of File Names

I am reading a SD card and I want to store an array that contains the file names that are on a file here is the code I’m using

File getDirectoryPage(File dir, int num) {
   File entry;
   char* fName[num];
   for(int i=0; i<num; i++) {
     entry = dir.openNextFile();
     fName[i] =;
   return dir;

When I use it to do 5 names all entries in the FName array points to the last name. Is there a better way to store into an array of strings? Thanks.

Edit: Added code tags

fName[i] =;

Presumably, it was the lack of code tags that caused the [ i ] to disappear.

OP, you are creating an array of pointers. Each time you get a file name, you point to the memory location where that name is stored. So, at the end, all 5 pointers point to the same place.

You want to use strdup() to copy the data that points to, to another location, and point the ith element at that location.

Thanks for the suggestions. I haven't used C in a long time so I have forgot some of the functions such as strdup.