Date: Wed, 01 Oct 1997 16:53:50 +0200 From: Hans-Bernhard Broeker Subject: Re: Problems with fread and fwrite To: Emyr DOT James AT astro DOT cf DOT ac DOT uk Cc: djgpp AT delorie DOT com Message-id: <01IOASQD92YY8WVYJT@mail> Organization: RWTH Aachen, III. physikalisches Institut B Content-transfer-encoding: 7BIT Newsgroups: comp.os.msdos.djgpp Precedence: bulk In article <60tlf0$7d3$1 AT loki DOT cf DOT ac DOT uk> you wrote: > I am trying to get djgpp to do a raw memory dump to a file. I wrote > the following small program to output 1000 double float > variables. The file produced should be exactly 8000 bytes > long. However, the program produces files with lengths that vary [...] [The code was posted separately, but it's simply enough, so I won't quote it] Short answer: See FAQ, question 9.3 Longer answer: The good-ole DOS textfile I/O strikes again. For binary data, you should always open your files with "wb" or "rb", and all will be well. This is documented both in the DJGPP libc docs (IIRC), and in the ANSI C Standard, and by K&R 2nd ed. Operating systems that don't make a difference between text and binary files (Unix, e.g.) are bound (if they state ANSI compliance) to ignore the "b", and for all others it is *mandatory*. HBB