int listdir(char *path, char *filelist[]) { DIR *dp; struct dirent *ep; int num = 0; /* open directory for reading */ if ((dp = opendir(path)) != NULL) { while ((ep = readdir(dp))) { filelist[num] = ep->d_name; /* add entry to file list */ num++; } closedir(dp); } else { perror("Error opening directory"); return 0; } return num; }