delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/01/10:56:44

Date: Wed, 01 Oct 1997 16:53:50 +0200
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
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
Newsgroups: comp.os.msdos.djgpp

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019