在xcode中用c编程打开文件 [英] Opening a file in c programming in xcode

查看:42
本文介绍了在xcode中用c编程打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个文件来打开一个文件并在 C 中读取该文件的内容.我使用的是 xcode,但文件指针返回一个 null 值.

I am trying to write a file to open a file and read the contents of that file in C. I am using xcode but the file pointer returns a value null.

int main(int argc, char** argv)
{    
    FILE *fp;
    fp=fopen("input.txt","r");
    if (fp==NULL)
        printf("error");
}

这将显示错误作为输出.有人可以帮我找到将文件 input.txt 放在项目中的正确位置吗?

This shows error as the output. Could someone help me to find the right place to put the file input.txt in the project?

推荐答案

该文件需要进入程序启动的当前目录".这是可配置的.在组和文件"窗格中,展开可执行文件"并选择您的可执行文件.按 Command-I 打开信息窗口.在常规"选项卡底部附近,您可以选择应用程序启动时的当前目录.

The file would need to go in the "current directory" where the program is launched. This is configurable. In the "Groups and Files" pane, expand "Executables" and pick your executable. Press Command-I to open the info window. Near the bottom of the "General" tab, you can select the current directory for when the application is launched.

这篇关于在xcode中用c编程打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆