Sometime: Debug Assertion Failed expression str!=NULL

Posted on 2006-05-04
Last Modified: 2013-11-20
Dear Experts,

I have just added a logging function into an existing program. Basically the program does alot of file convertion. It works fine until the logging function built in.

Im getting the error message like this:
Debug Assertion Failed!

Program: c:\file_extract\file_service.exe
File: fprintf.c
Line: 56

Expression: != NULL

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

(press Retry to debug the application)

The biggest problem is, this error message will only occur every 18 hours. this services will run every 2 minutes. when the error message occurs, the environment has no different as compare to 2 minutes before. the logging code:

void writeToZipLog(CString strMsg)
      //1) Only print into ZIPLog.txt when the string is NOT NULL
      //2) Print current date and time
      CTime datenow;
      datenow = datenow.GetCurrentTime();
      FILE *streamFile;
            streamFile      = fopen ("SBBZIPLog.txt", "a");
            fprintf (streamFile,"%s | %s\r\n", datenow.Format("%d-%m-%Y %H:%M:%S"), strMsg);
Question by:Heliumyap
    LVL 22

    Accepted Solution

    The C runtime library source code comes with VC++, so you can inspect fprintf.c for yourself.  Here's the relevant part:

    int __cdecl fprintf (
            FILE *str,
            const char *format,
     * 'F'ile (stream) 'PRINT', 'F'ormatted
            REG1 FILE *stream;
            REG2 int buffing;
            int retval;
            va_start(arglist, format);

            _ASSERTE(str != NULL);      <-- THIS IS LINE 56
            _ASSERTE(format != NULL);

    It would appear that you're passing a NULL pointer as the first argument in a call to fprintf.  

    Are you sure that your FILE* was successfully set?  Perhaps your file open or create failed.

    Check your file is successfully opened is append mode by using if(streamFile!=NULL)...and also include full path in fopen() while passing file name.



    Author Comment

    I have tripple confirm that no other application is using the file.

    i have set the if(streamFile!=NULL)... and if it really happens, write to another file. start from tomorrow morning, i should be able to see if it really happening.

    i wish to write it to EvenLog. but in VC++ is just too tedious. btw, do you know any website sharing how VC++ should write to windows evenlog?

    LVL 22

    Expert Comment

    LVL 22

    Expert Comment

    Also 'Simple class to fire messages to Windows EventLog'

    and Event Logging section at codeproject



    Author Comment

    Hi Mahesh,

    Oh no.. IT is still the same event i have the if(streamFile!=NULL) statement in the code.  

    however, i remind this line of code:
    streamFile     = fopen ("SBBZIPLog.txt", "a");

    This program has been running for more than 6 days before it hit the "Debug Assertion Failed" error.

    any more idea?
    LVL 22

    Expert Comment

    Have you checked that without using fopen..means using MFC class CFile etc ?


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    How to trace the cause of Out Of Memory issues 8 57
    Rewrite URL With Encoded Characters 6 57
    if loop in java 3 99
    fix34  challenge 9 72
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now