problem with TC2.0: read()/write()
Scott Amspoker
scott at bbxsda.UUCP
Fri Dec 22 03:02:26 AEST 1989
In article <352 at yetti.UUCP> asst-jos at yetti.UUCP (Research Assistant--Jonathan) writes:
> Hi, I am just starting to write a program in C, and I was experimenting
>with open(), close(), etc so I could read data in fixed blocks. I am
>working with Turbo C 2.0 , and the problem is that the program sometimes
>works and sometimes doesn't. I figure every write is 64 bytes, so the file
>'database' should always be a multiple of 64. Unfortunately, this isn't
>always true, sometimes it works, and a write adds all 64 bytes, and every
>once in a while it adds a few bytes for the heck of it.
You got bit by the text mode/binary mode problem. C compilers running
under MS-DOS must deal with the problem that MS-DOS uses both a
carriage return and a line feed to terminate a line of text. The I/O
libraries that come with these compilers provide two access modes to
files: text and binary. Text mode (default) removes the extra carriage
returns when reading and adds carriage returns to line feeds when writing.
Binary mode works the way you are expecting. You may indicate binary
mode as an option in your open() call. See the manual for details.
--
Scott Amspoker
Basis International, Albuquerque, NM
(505) 345-5232
unmvax.cs.unm.edu!bbx!bbxsda!scott
More information about the Comp.lang.c
mailing list