Date: Thu, 29 Jul 1999 11:30:29 +0300 (IDT) From: Eli Zaretskii 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: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.