fopen返回null并且perror打印无效的参数 [英] fopen returns null and perror prints invalid argument

查看:525
本文介绍了fopen返回null并且perror打印无效的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为"test"的文件,但无法使用fopen打开它. 这是代码-

I created a file named "test" but I'm unable to open it using fopen. Here is the code-

#include<stdio.h>
int main()
{
    FILE *fp;
    fp=fopen("test.txt","r");
    if(fp==NULL)
    {
        perror("Error: ");
    }
    fclose(fp);
    return 0;
}

运行上面的代码时,得到以下输出:

When I run the above code, I get the following output:

Error: Invalid argument

可能是什么原因? perror何时返回无效参数"错误消息?

What could be the reason? When does perror return "Invalid argument" error message?

推荐答案

看看 man fopen :

EINVAL提供给fopen(),fdopen()或freopen()的模式无效.

EINVAL The mode provided to fopen(), fdopen(), or freopen() was invalid.

可能test.txt不可读.

这篇关于fopen返回null并且perror打印无效的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆