fopen not work with XCode

萝らか妹 提交于 2019-12-24 05:59:28

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/13531331/fopen-not-work-with-xcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!