delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/29/18:49:57

Date: Thu, 29 Jul 1999 11:30:29 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: nine1one AT juno DOT com
cc: djgpp AT delorie DOT com
Subject: Re: Problems with file I/O and the value 13 (EOF?)
In-Reply-To: <19990728.061228.-4108575.0.nine1one@juno.com>
Message-ID: <Pine.SUN.3.91.990729113006.25908U-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Wed, 28 Jul 1999 nine1one AT juno DOT com wrote:

>   I am having problems with reading and writing to disk files with the
> standard C I/O libraries. I am writing a program that needs to read and
> write values from disk. I have a record of strings and short integers.
> Whenever I write the value 13 to a file and read it back I get a large
> number, as if it shifted bytes and is reading a value in the upper byte
> of the short integer.
[snip]
> /* create the file of 15 records */
> fptr=fopen("junk","w");

Here's your problem: you read and write binary data, but you didn't
use the "wb" and "rb" modes to open the file in binary mode.  So 13
(an ASCII code for a Newline) gets converted to the CR-LF pair and
corrupts your data file.  See section 9.3 of the DJGPP FAQ list, for
more on this.

- Raw text -


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