Mail Archives: djgpp/1999/07/29/18:49:57
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 -