gpt4 book ai didi

C - 无法从 Xcode 创建新的 .txt 文件

转载 作者:太空宇宙 更新时间:2023-11-04 00:36:06 26 4
gpt4 key购买 nike

我刚开始使用 Xcode 进行 C 编程。但是我现在有一个问题。我写了这段代码:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, const char * argv[]) {

FILE *fp;

fp = fopen("toto.txt", "w+");
fputs("hi", fp);

fclose(fp);

return 0;
}

由于toto.txt不存在,本该创建并打开它,但没有任何反应,我不知道为什么。

最佳答案

我认为您的问题与 Xcode 当前工作目录设置有关。您需要更新项目的当前方案。

  1. 停止运行您的应用程序。
  2. 转到产品 -> 方案 -> 编辑方案。

  1. 从左侧面板中选择“运行”->“选项”并选中“工作目录”- 使用自定义工作目录。

现在您的 C 项目将知道应该在哪里写入输出文件。

关于C - 无法从 Xcode 创建新的 .txt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35551131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com