Sunday, July 26, 2009

Why fclose() doesn't work for me in c++?

Hi, I'm using fclose() and it crahses my program.. is there any common mistakes beginners make with this function? Or is there an easy way to test why fclose() doesn't work? Oddly, enough, it doesn't crash when I'm running it in debug mode from Visual C++ 2005 (express edition) but when I run it from the command line, it crahses.

Why fclose() doesn't work for me in c++?
It could very well be that the file you are accessing in debug mode is not the same file that you are accessing (if at all) when you are running from the command line. Be sure to print out or other wise display the path name of the file you think you are accessing in your program. The function is most likely to fail if you are using a bad file descriptor.
Reply:Sorry, but we aren't psychic. You need to post code for us to see problems in it.





If fclose is the problem, then check the file pointer you are passing to it. Is it pointing to a valid stream?





Debug mode has additional side effects (initializing all variables to 0, automatically, is one example).

garden

No comments:

Post a Comment