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
.
It's because your root directory is not the working directory of your IDE. Either change the configuration to use your root directory as your IDE's working directory, or put name.txt in your IDE's working directory.
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