fopen() not working in C

后端 未结 4 975
北恋
北恋 2020-12-21 18:29

I got it fixed. Thanks for all the help.

I\'ve now looked through quite a few articles, forum posts and topics here; however, none have actually fixed my issue. The

相关标签:
4条回答
  • 2020-12-21 18:45

    The file is created, but not where you expect it to be.

    Check the working directory (getcwd).

    0 讨论(0)
  • 2020-12-21 18:56

    Try perror. It's possible you don't have permissions or something like that.

    FILE *receipt = fopen("receipt.txt", "w");
    if (!receipt)
        perror("fopen");
    
    0 讨论(0)
  • 2020-12-21 19:00

    The only explanations that makes sense are that you don't have permissions to create the file in the working directory, or the working directory is not where you are looking for the file to be created.

    fopen() not working

    Well, of course it works. You shouldn't get in the mindset that the standard library doesn't work.

    No warnings/notices or otherwise stuff to give me any idea of what is wrong.

    You did not check for errors after calling fopen(). If you don't check for errors, how do you expect them to be delivered to you?

    0 讨论(0)
  • 2020-12-21 19:08

    You should use strerror to format the error yourself or perror to print the system error matching with the errno.

    man errno may help you

    0 讨论(0)
提交回复
热议问题