gpt4 book ai didi

c - 断言错误: involving the fscanf function

转载 作者:行者123 更新时间:2023-11-30 20:56:54 30 4
gpt4 key购买 nike

我的程序中出现此错误:

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++;
}
}

Additional questions! I am encountering several similar errors. The programs breaks at different portions of source codes and some of which are built in functions like "fscanf". I do not know the reason. And sometimes a program on my computer, like "Flash Player" notifies me of some sort of error. Is this because the pointers used in my program are trying to access "Flash Player"? Why is this happening and what is the possible fix?

简单来说什么是断言错误?

致@Jonathan Leffler

#ifdef _DEBUG
/*
* Report error.
*
* If _CRT_ERROR has _CRTDBG_REPORT_WNDW on, and user chooses
* "Retry", call the debugger.
*
* Otherwise, continue execution.
*
*/

if (rterrnum != _RT_CRNL && rterrnum != _RT_BANNER && rterrnum != _RT_CRT_NOTINIT)
{
switch (_CrtDbgReportW(_CRT_ERROR, NULL, 0, NULL, L"%s", error_text))
{
-> case 1: _CrtDbgBreak(); msgshown = 1; break;
case 0: msgshown = 1; break;
}
}

其中 -> 是意外断点。位于 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()失败时,它返回一个NULL指针,并且断言说stream != NULL(其中'stream'是一个文件流,的第一个参数>fscanf(),表示FILE *例如fp`)。

您使用 fscanf_s() 的可能性很大,因为您使用的是 Windows — 这是相同的基本情况,但 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...

关于c - 断言错误: involving the fscanf function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18544049/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com