From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: fclose??? Date: 12 Mar 2001 12:28:33 GMT Organization: Aachen University of Technology (RWTH) Lines: 45 Message-ID: <98ifdh$k4j$1@nets3.rz.RWTH-Aachen.DE> References: <3AAAE89C DOT 6050002 AT operamail DOT com> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 984400113 20627 137.226.32.75 (12 Mar 2001 12:28:33 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 12 Mar 2001 12:28:33 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Sahab Yazdani wrote: > Hello everybody, i'm having a whole string of strange problems which > seem to be very loosely interconnected. The first is that my program is > crashing with a call to fclose. I've checked the pointers and they seem > to be fine (as far as I can tell). The code is supposed to open a > Windows Bitmap (BMP) file and store it in an linear array: One *very* likely reason that this would fail is this line: > fread( &header, sizeof( BMPHeader ), 1, in ); For this line to work correctly, you have to define the BMPHeader struct in a special way (keyword: packed structures). If you don't, the data extracted by these statements: > length = header.Width; > width = header.Height; > bitDepth = header.BitCount; may very easily be bit garbage, and lead to totally insane behaviour of the rest of the code. [...] > SECOND problem: calls to new and delete are causing erratic problems, This, however, indicates that your real problem may as well be completely unrelated to the piece of code that crashes. Crashes in 'new' (or free(), or any functions that calls free(), like fclose() my well do) almost 99% of the time are due to writes past the ends of arrays, elsewhere in the program. You should test your program with the YAMD heap access debugger to find where the real error is. > PPS. On a side note, RHIDE has decided that whenever I go to > File|Open... it defaults to the djgpp/bin/ directory... this is really > annoying as my working directories are nowhere near there... It's *not* RHIDE that decided that. It was you, when you set up a desktop link to RHIDE. Don't do that. Start RHIDE from the command line after CD'ing to the director with the sources, instead. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.