Reputation: 63
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 warning generated. 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)
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;
}
Upvotes: 0
Views: 622
Reputation: 370407
Undefined symbols for architecture x86_64: "_changeDirectoryAndGetFileName", referenced from: _changeDirectoryAndGetFilename
Notice the capitalization of the n
in the name of the called function compared to the calling function. In other words: changeDirectoryAndGetFilename is indeed defined, but changeDirectoryAndGetFileName (with a capital N) is not.
Upvotes: 2