简体   繁体   English

递归调用C中的函数隐式声明

[英]Implicit declaration of function in recursive call C

I'm trying to write a recursive function to list out all the directories until a regular file is inputted but I get the following error: 我试图编写一个递归函数以列出所有目录,直到输入常规文件,但出现以下错误:

1.c:25:21: warning: implicit declaration of function 'changeDirectoryAndGetFileName' is invalid in C99 [-Wimplicit-function-declaration] if(!isFile(sf)) changeDirectoryAndGetFileName(); 1.c:25:21:警告:函数'changeDirectoryAndGetFileName'的隐式声明在C99中无效[-Wimplicit-function-declaration] if(!isFile(sf))changeDirectoryAndGetFileName(); ^ ^

1 warning generated. 产生1条警告。 Undefined symbols for architecture x86_64: "_changeDirectoryAndGetFileName", referenced from: _changeDirectoryAndGetFilename in 1-b3c344.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 体系结构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;
}

Undefined symbols for architecture x86_64: "_changeDirectoryAndGetFile N ame", referenced from: _changeDirectoryAndGetFile n ame 对于架构x86_64的未定义的符号:“_changeDirectoryAndGetFileÑAME”,从引用:_changeDirectoryAndGetFileÑAME

Notice the capitalization of the n in the name of the called function compared to the calling function. 请注意,与调用函数相比,被调用函数名称中n的大写字母。 In other words: changeDirectoryAndGetFile n ame is indeed defined, but changeDirectoryAndGetFile N ame (with a capital N) is not. 换句话说:确实定义了changeDirectoryAndGetFile n ame,但是未定义changeDirectoryAndGetFile N ame(大写N)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM