I am writing a routine to return a list of files in a directory in C. The routine takes the directory name and a maximum value for the number of files. I want it to be portable. And I'd like to get rid of the warning that **file_list is not initialized. Comments and help. thanks.
Code:
#include <stdio.h>
#include <stdlib.h>
#define num_files 100
void get_file_list( char * dir, char ** file_list);
int main(int argc, const char * argv[])
{
char **file_list, *dir;
dir = (char *) calloc(25, sizeof(char));
file_list = (char **) calloc(25, sizeof(char*));
get_file_list(dir, file_list);
return 0;
}
void get_file_list( char * dir, char ** file_list)
{
int i;
file_list = (char **) calloc(num_files, sizeof(char*));
for (i = 0; i < num_files; i++)
file_list[i] = (char *) calloc(25, sizeof(char));
//code
}