我正在使用 scandir 来匹配目录中的某些文件。match 函数接受const struct dirent *dp
参数。
但我还需要用它传递另一个论点。当我尝试这样做时,compiles 会给我一个警告(不是错误),我的 match 函数是不兼容的指针类型。
是否不允许将另一个参数传递给匹配函数?如果不是,我可能不得不将我不想做的特定变量设为全局变量。
代码片段:
/* below I am adding new argument - char *str */
match_function (const struct dirent *dp, char *str) {
}
function() {
count = scandir(PATH, &namelist, match_function, alphasort);
}
警告:
warning: passing argument 3 of 'scandir' from incompatible pointer type