fprintf调试断言失败 [英] fprintf debug assertion fail

查看:1894
本文介绍了fprintf调试断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,如果我手动启动正确运行。但是,如果我尝试添加一个注册表项在启动时自动启动它,我得到这个错误:

 调试断言失败str!= null)fprintf.c line:55 



以下是代码:

  main()
{
FILE * filetowrite;
filetowrite = fopen(textfile.txt,a +);

writefunction(filetowrite);
}

int writefunction(FILE * filetowrite){

fprintf(filetowrite,%s,\\\
\\\
);
...
}



我还尝试传递文件名为 char * 并在 writefunction()中打开,但我得到相同的错误。

解决方案

fopen 失败。您应该始终检查返回值,以查看其是否有效:

  filetowrite = fopen .txt,a +); 
if(filetowrite == NULL){
//记录一些东西,包括errno
exit(1);
}

第55行fprintf.c 在VC ++中是:

  _VALIDATE_RETURN((str!= NULL),EINVAL,-1); 

其中 str FILE * 参数(nice变量名,Microsoft,您在想什么?)



我怀疑可能存在权限问题或者类似的尝试通过注册表运行它(大概在运行 RunOnce 或作为服务)。 / p>

一旦你弄清楚实际错误是什么,解决方案应该更容易产生。



这是一个权限的问题,你应该能够通过使用 c:\\a\\directory\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ i \\can\\write\\to\\textfile.txt ,看看它是否工作。



如果简单地证明background启动方法在错误的目录中,请将目录更改为您的计划的第一个动作之一。


I have a program that runs correctly if I start it manually. However, if I try to add a registry key to start it automatically during startup, I get this error:

Debug assertion failed (str!=null) fprintf.c line:55

I tried to add Sleep(20000) before anything happens, but I get the same error.

Here's the code:

main()
{
    FILE* filetowrite;
    filetowrite = fopen("textfile.txt", "a+");

    writefunction(filetowrite);
}

int writefunction(FILE* filetowrite) {

    fprintf(filetowrite, "%s", "\n\n");
    ...
}

I also tried passing the filename as char* and opening it in writefunction(), but I get the same error.

解决方案

The fopen is failing. You should always check the return value to see if it works:

filetowrite = fopen("textfile.txt", "a+");
if (filetowrite == NULL) {
    // log something, including errno
    exit (1);
}

Line 55 of fprintf.c in VC++ is:

_VALIDATE_RETURN( (str != NULL), EINVAL, -1);

where str is the FILE * argument (nice variable name, Microsoft, what on Earth were you thinking?).

I suspect there may be permissions problems or something similar with trying to run it via the registry (presumably under Run or RunOnce or as a service).

Once you've figured out what the actual error is, the solution should be easier to produce.

If it's a matter of permissions, you should be able to find that out by using something like c:\\a\\directory\\i\\KNOW\\i\\can\\write\\to\\textfile.txt and seeing if it works. Then you can also use that file for logging things like the current directory.

If it simply turns out the "background" starting method is in the wrong directory, change directories as one of your program's first actions.

这篇关于fprintf调试断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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