FOPEN返回null - PERROR打印参数无效 [英] fopen returns null - Perror prints Invalid argument

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

问题描述

简单的fopen操作似乎不起作用。 PERROR回报 - 参数无效。什么可能是错误的。

我有R中称为abc.dat一个ASCII文件:

  INT的main()
{
    FILE * F =的fopen(R:\\ abc.dat,R);
    如果(!F)
    {
        PERROR(出现以下错误);        返回1;
    }
}

输出:


  

出现以下错误:无效的参数



解决方案

让您远离 \\ 。它必须是 \\\\ 在字符串中使用时。

  FILE * F =的fopen(R:\\\\ abc.dat,R);

否则,该字符串由的fopen 看到被包括 \\ A 提醒转义序列是无效参数吧。

通用转义序列和它们的宗旨是:

  \\一个扬声器发出蜂鸣
\\\\反斜杠字符\\ b退格(移动光标,没有擦除)
\\ f换页(打印机弹出页面;屏幕上的字符安赫)
\\ n换行,像pressing回车键
\\ r回车(光标移动到该行的开头)
\\ t制表
\\ v垂直制表(光标向下移动一行)
\\'撇号
\\双引号字符
\\?问号
\\ 0空字节(反斜杠零)
\\ xnnn十六进制字符值(基数为16)
\\ Xnnn十六进制字符值(基数为16)

The simple fopen operation seems to not work. perror returns - Invalid argument. What could be wrong.

I have a ascii file called abc.dat in R:.

int main()
{
    FILE *f = fopen("R:\abc.dat","r");
    if(!f)
    {
        perror ("The following error occurred");

        return 1;
    }
}

Output:

The following error occurred: Invalid argument.

解决方案

Escape your \. It must be \\ when used in the string.

FILE *f = fopen("R:\\abc.dat","r");

Otherwise, the string is seen by fopen to be including the \a "alert" escape sequence which is an invalid argument to it.

Common escape sequences and their purposes are:

\a  The speaker beeping
\\  The backslash character

\b  Backspace (move the cursor back, no erase)
\f  Form feed (eject printer page; ankh character on the screen)
\n  Newline, like pressing the Enter key
\r  Carriage return (moves the cursor to the beginning of the line)
\t  Tab
\v  Vertical tab (moves the cursor down a line)
\’  The apostrophe
\"  The double-quote character
\?  The question mark
\0  The "null" byte (backslash-zero)
\xnnn   A character value in hexadecimal (base 16)
\Xnnn   A character value in hexadecimal (base 16)

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

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