Tuesday, July 28, 2009

What does this message in visual studio 2005 mean?

"Debug Assertion Failed!





Program:...


File: fgets.c


Line: 57





Expression: (str!=NULL)





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





(Press Retry to debug the application)"


I have no idea how to fix this... I tried to debug, but i don't understand anything...





Another thing, why do we type srand(time(NULL)) before using rand()???


NOTE: I am working on a win32 console application

What does this message in visual studio 2005 mean?
You should read up on assertions. They are a very important debugging tool. In C there is a function called assert and you pass it a test condition. like assert( varible1 %26gt; varible2 );





If the assertion is false it will crash your program giving you the filename, and line number of the assertion that crashed your program. That way you know you have a bug, and you know where.





The assertion in your code is telling you that str is NULL. Meaning it is empty, deleted, or blank and you are trying to read data from it. You can't read data from something that is NULL that's why the assertion is failing.





The reason you see srand(time(null)) before using rand is because rand generates fake random numbers. They're not real random numbers because it is very hard for a computer to create real random numbers. So srand seeds rand with a number. Then rand will create a list of sort of random numbers that you can use for testing and games.





But if you send the same number to srand you will get the same exact list back from rand. So many programmers use the time in milliseconds as a seed value for the random list so it is at least a litte unpredictable.


No comments:

Post a Comment