Unable to open a file with fopen()

后端 未结 8 958
盖世英雄少女心
盖世英雄少女心 2020-12-03 18:21

I\'ve been trying to open a file and output text, but I keep getting errors. So I thought I would start at the very beginning and just try opening the file. This is my cod

相关标签:
8条回答
  • 2020-12-03 18:52

    Your executable's working directory is probably set to something other than the directory where it is saved. Check your IDE settings.

    0 讨论(0)
  • 2020-12-03 19:00

    Well, now you know there is a problem, the next step is to figure out what exactly the error is, what happens when you compile and run this?:

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
        FILE *file;
        file = fopen("TestFile1.txt", "r");
        if (file == NULL) {
          perror("Error");
        } else {
          fclose(file);
        }
    }
    
    0 讨论(0)
提交回复
热议问题