1
votes

there is debug assertion failed error. Can someone get to the probem.

Debug Assertion Failed !

Program:..
File:fclose.c
Line:47

Expression:(stream!=Null)

I am debugging the code in visual studio.

Here is the Part of the code:

int __cdecl fclose (
        FILE *stream
        )
{
        int result = EOF;

        _VALIDATE_RETURN((stream != NULL), EINVAL, EOF);

        /* If stream is a string, simply clear flag and return EOF */
        if (stream->_flag & _IOSTRG)
                stream->_flag = 0;  /* IS THIS REALLY NEEDED ??? */

        /* Stream is a real file. */
        else {
                _lock_str(stream);
                __try {
                        result = _fclose_nolock(stream);
                }
                __finally {
                        _unlock_str(stream);
                }
        }

        return(result);
}
1
Run in the debugger, when the assertion happens the program will stop, and you can go up the call stack to your code. There you can see that you're passing a NULL pointer to fclose which is what the assertion is about. Check your code to see why you call fclose with a NULL pointer, maybe you forgot to check the return from fopen? - Some programmer dude

1 Answers

1
votes

Check the callers of fclose(). Don't feed a NULL FILE* to it.