Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fopen not work with XCode

Tags:

c

text-files

The function fopen(FILE *fp) in XCode it's not working, I put the text file in the root directory, but not work, it's weird because, executing from terminal works fine, but executing from IDE not.

The sintax that I use it's this:

FILE *fp=fopen("name.txt", "r");
if(fp==NULL)
{
    printf("the text file can't be opened");
    exit(0);
}
else
    return fp;

And always return NULL.

like image 514
Chepeman Avatar asked Nov 27 '22 17:11

Chepeman


1 Answers

well what's the working directory when run via xcode?
by default IIRC it isnt set and that might be the difference between IDE and terminal.

-- set the working dir:

go to: product > scheme > edit scheme...

there go to:
options tab and choose a working directory

like image 167
Daij-Djan Avatar answered Dec 19 '22 07:12

Daij-Djan