我不明白为什么我的 C 编译器会抛出一个严重的错误。我根据 man page 初始化了所有东西,或者至少我认为我做了。 .然而我仍然被抛出一个严重的错误。它一直说 expected int (*)(const struct dirent *) but argument is of type 'int (*)(struct dirent *)'
我的代码:
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 this directory.\n");
}
else
{
printf("Number of files = %d\n", count);
for (i = 1; i < count+1; i++)
{
printf("%s ",files[i-1]->d_name);
printf("\n");
}
return 1;
}
pathname = char pathname[MAXPATHLEN];
文件选择 =
int file_select(struct direct *entry)
{
if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0))
return (FALSE);
else
return (TRUE);
}
最佳答案
您需要更改回调函数,使其参数符合预期:
int file_select(const struct direct *entry)
{
.
.
.
}
关于c - 如何摆脱预期的 'int(*)(const struct dirent *)' 但参数类型为 'int (*)(struct dirent *)' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30182345/