Thread: Fseek() debug assertion failed

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    Exclamation Fseek() debug assertion failed

    Most of the time fseek works smooth, but on some occasion, fseek is crashing application. It will be helpful if one can help finding the bug.
    pfile is global pointer variable.


    Code:
    FILE* pfile;
    
    void WriteToFile(char *text)
    {	
    	long filesize;
    	if (pfile) {
    		fprintf(pfile,"%s", text);
    		fflush(pfile);
    	}
    	fseek (pfile, 0, SEEK_END);
    	filesize=ftell (pfile);
    	if ( (long)LOG_FILE_SIZE < filesize) {
    		fclose(pfile);
    		pfile = NULL;
    		CreateLogFile();
    	}
    }

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    This is a C question and not a C++ question.

    However without knowing the how WriteToFile is called, what you have done before that and so on it is hard to tell...do you check that a file is properly opened before calling WriteToFile (I see you do a check in the function but that is only done before writing to the file, you may attempt to seek using an invalid file handle)?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. debug assertion failed
    By khoavo123 in forum C Programming
    Replies: 1
    Last Post: 04-15-2011, 08:21 AM
  2. Debug Assertion Failed
    By Freddy92 in forum C++ Programming
    Replies: 4
    Last Post: 01-30-2011, 03:52 PM
  3. Debug Assertion Failed!
    By IndioDoido in forum C Programming
    Replies: 31
    Last Post: 03-25-2008, 11:07 AM
  4. debug assertion failed !
    By blue_gene in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2004, 11:23 AM

Tags for this Thread