how to put files of folder in an array

i have a function that returns the path of a directory in
char file_name;
i need to find how many *.wrl files are in the folder
and put in an array of strings called
"file_body"
all the wrl file names in the folder
such as:
filebd[0]="cube.wrl"
filebd[1]="triangle.wrl"
...
all the files of the folder should be in the array, each in a different cell...
( i dont know how many cells are in the array...) - should make malloc...
thnx
niriaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:

You'll need an array of strings to hold the file names.  Better yet, an array of string pointers.  You'll also need to call findfirst() and findnext() to read through the filenames in the directory.   (These are standard functions available in both unix and windows programming.)

This sounds like it may be homework, so I'll get you through the string pointer table, and you research findfirst() and findnext().

Kent



char **FileNames = NULL;
int    FileCount = 0;


AddNameToList (char *Name)
{
  FileNames = (char **) realloco (FileNames ((FileCount+1) * sizeof (char *)));
  FileNames[FileCount++] = strdup (Name);
}


0
All Courses

From novice to tech pro — start learning today.