[英]Implicit declaration of function in recursive call C
我试图编写一个递归函数以列出所有目录,直到输入常规文件,但出现以下错误:
1.c:25:21:警告:函数'changeDirectoryAndGetFileName'的隐式声明在C99中无效[-Wimplicit-function-declaration] if(!isFile(sf))changeDirectoryAndGetFileName(); ^
产生1条警告。 体系结构x86_64的未定义符号:“ _ changeDirectoryAndGetFileName”,引用自:1-b3c344.o中的_changeDirectoryAndGetFilename
Here is my code:
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
void listCurrentDirectory(){
DIR *d;
struct dirent *entry;
d = opendir(".");
while((entry=readdir(d)) != NULL)printf("%s\n", (*entry).d_name);
closedir(d);
}
int isFile(char *fname){
struct stat pstat;
stat(fname, &pstat);
return S_ISREG(pstat.st_mode);
}
char *changeDirectoryAndGetFilename(){
listCurrentDirectory();
char sf[] = "Placeholder";
scanf("%s", sf);
printf("File selected: %s\n", sf);
if(!isFile(sf)) changeDirectoryAndGetFileName();
return "d";
}
int main(int argc, char *argv[]){
if(argc != 2){
printf("code(-c) or decode(-d)\n");
return 1;
}
changeDirectoryAndGetFilename();
return 0;
}
对于架构x86_64的未定义的符号:“_changeDirectoryAndGetFileÑAME”,从引用:_changeDirectoryAndGetFileÑAME
请注意,与调用函数相比,被调用函数名称中n
的大写字母。 换句话说:确实定义了changeDirectoryAndGetFile n ame,但是未定义changeDirectoryAndGetFile N ame(大写N)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.