【问题标题】:"can't find the specified file" error, when I debug a program“找不到指定的文件”错误,当我调试程序时
【发布时间】:2021-03-10 00:36:24
【问题描述】:

我正在编写一个非常基本的程序,在 .txt 文件上打印数字 10, 当我尝试调试它时出现问题,Visual Studio 向我显示一个错误窗口“找不到指定的文件”。 (它是用 C 写的)

这是我的代码:

  #include <stdio.h>
    #include <stdlib.h>
    #define _CRT_SECURE_NO_WARNINGS
    
    int main() {
        FILE* f = fopen("file.txt", "w"); 
        if (f == NULL) {
            exit(1);
        } 
        int number = 10; 
        fprintf(f, "a number: %d\n", number); 
    
        fclose(f); 
    
        return 0; 
    } 

【问题讨论】:

    标签: c file printf stdio


    【解决方案1】:

    如果文件尚不存在,则需要将标志"w+" 放入fopen 以创建文件。

    【讨论】:

      猜你喜欢
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 2017-12-16
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多