c - 在 C Issue 中打开和创建文件?

标签 c xcode file io codeblocks

所以,我用 C 编写了一个简单的程序,它打开一个名为 prog6_input.txt 的文件并生成另一个名为 prog_output.txt 的文件.但是,下面的代码在 Windows 上完美运行,但在 Mac 上编译时会失败。 (我还假设这在创建文件时也有同样的问题)

FILE *ptr_file = fopen("prog6_input.txt", "r");

// We Don't have a input file
if(!ptr_file) {
    perror("Error Reading Input file.\n");
    return 1;
}

对于错误:没有这样的文件或目录

如以下屏幕截图所示,该文件位于同一目录中。这适用于 Windows,但不适用于 Mac OSX?为什么会这样,我该如何解决?

更新:为了 vompile,我使用终端在目录中使用 make main

enter image description here

最佳答案

您应该打开一个终端,cd 到您的 Prog6 目录,然后使用 ./main 运行您的可执行文件。

关于c - 在 C Issue 中打开和创建文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33839550/

相关文章:

ios - 键盘扩展内存泄漏?

linux - 如何将 "command -i interval | tail"输出写入文件

c - 为什么这个管道会起作用?

c - 将整数值分配给结构

c - 如何获取串口RS232输出的脉冲?

android - react-native-linkedin-sdk - 无法读取未定义的属性 'configure' (LinkedInSessionManager.ios.js)

json - 使用 Alamofire 进行 GET 请求调用后没有响应

python - PyQt 将文件名传递给常用函数

java - 尝试写入文件时出现 FileNotFound 异常

无法设置esp8266 arduino的Station only模式