delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/09/09:15:13

Message-Id: <3.0.16.19971009151313.33272e56@hem1.passagen.se>
Date: Thu, 09 Oct 1997 15:13:16 -0400
To: Emyr DOT James AT astro DOT cf DOT ac DOT uk
From: Peter Palotas <blizzar AT hem1 DOT passagen DOT se>
Subject: Re: Problems with fread and fwrite
Cc: djgpp AT delorie DOT com
Mime-Version: 1.0

At 14.07 1997-10-01 GMT, 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
>each time but are typically 8020 bytes long. Needless to say, replacing
the fwrite
>to an fread to read in the file produces garbage. What is going on ??
>Is there another way of doing it ? 
>I tried the program with gcc 2.6.3 on a Sun workstation and that works ok
(i.e 
>output files are 8000 bytes long and can be read in to give meaningful
values).
>HELP!!!!
>

Well, this must be the most commonly asked question around here. And I am
99.99% certain that your problem is that you did not open the file in
binary mode. Under UNIX that doesn't make any diffrence, but in DOS it
surely does!

use FILE *fin = fopen("file.out", "wb");

-- Peter Palotas alias Blizzar -- blizzar AT hem1 DOT passagen DOT se --

*****************************************************
* A brief description of DJGPP:                     *
* NEVER BEFORE HAS SO FEW DONE SO MUCH FOR SO MANY! *
*****************************************************

- Raw text -


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