c - How do I get rid of the expected 'int(*)(const struct dirent *)' but argument is of type 'int (*)(struct dirent *)' error? -
i don't understand why c compiler throwing dirent error. initialized everything, or @ least thought did, in according man page. , yet still getting thrown dirent error. keeps saying expected int (*)(const struct dirent *) argument of type 'int (*)(struct dirent *)'
my code:
extern int alphasort(); int count, i; struct direct **files; if(!(getcwd(pathname, sizeof(pathname)))) { die("error getting pathname\n"); } printf("current working directory = %s\n", pathname); count = scandir(pathname, &files, file_select, alphasort); if (count < 0) { die("no files in directory.\n"); } else { printf("number of files = %d\n", count); (i = 1; < count+1; i++) { printf("%s ",files[i-1]->d_name); printf("\n"); } return 1; } pathname = char pathname[maxpathlen];
file_select =
int file_select(struct direct *entry) { if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) return (false); else return (true); }
you need change callback function argument matches expected:
int file_select(const struct direct *entry) { . . . }
Comments
Post a Comment