Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
断言错误:涉及fscanf函数_C_Runtime Error_Scanf - Fatal编程技术网

断言错误:涉及fscanf函数

断言错误:涉及fscanf函数,c,runtime-error,scanf,C,Runtime Error,Scanf,此错误发生在我的程序中: Debug Assertion Failed! Program:C:\JM\.\bin\ldecod.exe File: f:\ff\vctools\crt_bld\self_x86\crt\src\fscanf.c Line:52 Expression: (stream!=NULL) For information on how your program can cause an assertion failure, see the Visual C++ doc

此错误发生在我的程序中:

Debug Assertion Failed!

Program:C:\JM\.\bin\ldecod.exe
File: f:\ff\vctools\crt_bld\self_x86\crt\src\fscanf.c
Line:52

Expression: (stream!=NULL)

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application.)
这里有什么问题吗

代码 这是我使用fscanf的代码部分。当mi=297时,它工作得非常好

int myframe[29699];
........

if (CONCEAL==1)
{
  FILE*concealfile;
  concealfile=fopen("myerrsim%15carphone.txt","r");
  for(mi=0; mi<14850; mi++)
  {
      fscanf(concealfile,"%d\n", &myframe[mi]);
  }
  if (myctr==currMB->mbAddrX+(((currMB)->p_Slice)->p_Img)->number*99 && currMB->mbAddrX+(((currMB)->p_Slice)->p_Img)->number>0)
  {
      if (myframe[myctr]==1)
      {
          mbmode=0;
      }
      myctr++;
  }
}
其中->是意外的断点。
位于C:\Program Files\Microsoft Visual Studio 11.0\VC\crt\src\crt0msg.C中,您似乎做了如下操作:

char name[64];
FILE *fp = fopen("c:/non-existent/file", "r");
fscanf(fp, "%s", name);
没有检查
fopen()
是否成功,并且
fprintf()
触发了断言失败。当
fopen()
失败时,它返回一个空指针,断言说
stream!=NULL
(其中“stream”是文件流,
fscanf()的第一个参数,表示文件*
,例如
fp`)

因为您在Windows上,所以您可能会使用
fscanf_s()
,这与基本情况相同,但是
fscanf_s()
检查
fscanf()
没有检查的问题

可能的解决方案:

char name[64];
FILE *fp = fopen("c:/non-existent/file", "r");
if (fp == 0)
    ...report failure to open file (and exit or return)...
if (fscanf(fp, "%s", name) != 1)
    ...report read failure...

等一下,它没有出现。我会再试一次。请复制/粘贴评论。.图像很难阅读,而且关于你的程序在
fscanf
调用中的信息非常少。显然我没有足够的声誉,这就是图像没有出现的原因。我已在文本中插入错误。对不起,我不明白我的问题有什么不清楚的地方。我不知道我不被允许提前发布照片。我已经编辑了我的问题。我甚至还把密码放进去了。我正在尽我所能把这个问题弄清楚。我的问题有什么不太清楚的?它在早些时候起作用了。但是,当我从正在读取的文本文件中添加更多要读取的文本时,出现了此错误。然后返回到工作版本或缩小的文本文件。或者显示代码,这样我们就可以看到你做错了什么。盲目工作(无论是因为我们试图阅读图像——现在已经不见了——还是因为我们没有你的代码)让生活变得艰难。最好是创建一个SSCCE()。好的,我很快就会发布它。我从文本文件中读取的是一个随机错误。我无法减小大小,因为所需的错误数为14850。我使用的297个错误只是为了测试我的程序是否正常工作。我已经在cmd中打开了程序的.exe文件。这是问题的可能原因吗?您没有按照我的假设检查文件是否已打开。您真的有一个名称中有
%
的文件吗?您也不会检查
fscanf()
的结果。您没有显示
myframe
的声明-事实上,您根本没有阅读如何创建SSCCE。可以想象,您会遇到麻烦,因为您在
myframe
数组中索引超出了范围,特别是当它似乎适用于较小的数字而不适用于较大的数字时。
char name[64];
FILE *fp = fopen("c:/non-existent/file", "r");
if (fp == 0)
    ...report failure to open file (and exit or return)...
if (fscanf(fp, "%s", name) != 1)
    ...report read failure...