Thread: error "debug assertion failed"

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do you pay heed to compiler warnings? Because if you used \ instead of \\, you would get warnings about invalid escape codes.
    Also, when you get a assertion, click break. It will break somewhere in the code. Go to the stack tab and work your way back to your function (your code). Then indicate to us which line the asseration was on, because assertion failed can mean a thousand things and we cannot know which one it is.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    @ Elysia,


    Okay i tried what you said. But the thing is that as you pointed out to go to the stack and then work my way back to the code to figure out where the exact line is. I am unable to see any stack tab throughout the Visual C menus and windows. It gave me three options to either abort, retry or ignore. I tried all three but still no where the stack tab shows.

    Any suggestions on how do i go to the stack tab. Anyhow i am attaching a screenshot of the error message that i got when i tried the program.

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Right there, the error is telling you the line of code with the error is 41, and shows the expression that caused the failure.

    You have been given everything that you need, right on a silver platter!

  4. #19
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    But the thing is that the line number 41 in my current code sample is a blank line. It has no C statements in it.

    Also i think that the line number it is referring to where the error has occured is in some file

    src\fgetc.c

    But this is not the file that i created. Any thoughts ?????

  5. #20
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    This file is where the actual definition of fgetc() is present. And this is the line which is reffered in the debugger.
    _VALIDATE_RETURN( (stream != NULL), EINVAL, EOF);
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you've made the changes that were given to you as answers on page one, you should not be receiving this error, anymore.

    If you haven't made those changes yet, please do so.

    If you still have problems, post up the new code, so we can see what you're now talking about.

  7. #22
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    Yes i made the changes as mentioned. But i was trying to get to the point what Elysia was referring to on how to figure out exact place where error occured.

    Anyhow the modified code is as follows:
    [insert]
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void){
    
    	FILE *fp;
    	int ch;
    	int nol= 0, not = 0, nob = 0, noc =0;
    
    	fp = fopen("C:\\Documents and Settings\\ROHAN\\Desktop\\DESKTOP\\filejava.txt", "r");
    	if(fp == NULL){
    		
    		printf("\n Error opening the file");
    		return 0;
    	}
    
    	while(1){
    	
    		ch = fgetc(fp);
    
    		if(ch == EOF)
    			break;
    
    		noc++;
    
    		if(ch == ' ')
    			nob++;
    
    		if(ch == '\n')
    			nol++;
    
    		if (ch == '\t')
    			not++;
    	}
    
    	fclose(fp);
    	printf("\n No of char = %d", noc);
    	printf("\n No of line = %d", nol);
    	printf("\n No of tab = %d", not);
    	printf("\n No of space = %d", nob);
    
    	return 0;
    }
    Its working perfectly fine.

  8. #23
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Go to the "View" pull down menu, select "Debug Windows" >> Call Stack (Alt+7), in VS C/C++ 6.0. Your version should be similar. Only available when you're actively debugging, of course.

  9. #24
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Remember that in the call stack you might see a lot of stuff that isn't your program. The call stack is basically a list saying, "main called a on line b, c called d on line e....". Your code might have called several other functions in the standard library before the error actually caused a problem, so just look for the last line that points to code YOU wrote.

    Just as another attempt at putting the EOF issue into laymen's terms, EOF is not a regular character. If you try to force every value you read be a character, you'll lose some information that can't be represented as chars. That's why you should read 'ints'. If you read ints, any regular character maintains it's original value and can be converted to a char for other purposes; but then you have the added benefit of reading information like EOF.

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by roaan View Post
    @ Elysia,

    Okay i tried what you said. But the thing is that as you pointed out to go to the stack and then work my way back to the code to figure out where the exact line is. I am unable to see any stack tab throughout the Visual C menus and windows. It gave me three options to either abort, retry or ignore. I tried all three but still no where the stack tab shows.

    Any suggestions on how do i go to the stack tab. Anyhow i am attaching a screenshot of the error message that i got when i tried the program.
    First click Retry to make the debugger break into the code.
    The call stack should be on your lower-right corner, where it says Call stack (see attached pic).
    Last edited by Elysia; 08-07-2009 at 10:11 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by roaan View Post
    Okay i tried what you said. But the thing is that as you pointed out to go to the stack and then work my way back to the code to figure out where the exact line is. I am unable to see any stack tab throughout the Visual C menus and windows. It gave me three options to either abort, retry or ignore. I tried all three but still no where the stack tab shows.
    To get to the stack trace you first have to dismiss that dialog by hitting "Retry."

    It was doing exactly what I thought it was.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  12. #27
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    Yes i can look into the call stack now and figure out the exact line where the error seems to happen............ :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Assertion Error with DoModal(), activated from a thread
    By hanhao in forum Windows Programming
    Replies: 1
    Last Post: 07-08-2005, 12:39 AM
  3. Assertion error when looking for window handle
    By axr0284 in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2005, 04:11 PM
  4. debug assertion failed !
    By blue_gene in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2004, 11:23 AM
  5. Assertion Failure
    By drdroid in forum Game Programming
    Replies: 9
    Last Post: 01-04-2003, 07:02 PM