Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!unmvax!bbx!bbxsda!scott From: scott@bbxsda.UUCP (Scott Amspoker) Newsgroups: comp.lang.c Subject: Re: problem with TC2.0: read()/write() Message-ID: <481@bbxsda.UUCP> Date: 21 Dec 89 16:02:26 GMT References: <352@yetti.UUCP> Reply-To: scott@bbxsda.UUCP (Scott Amspoker) Organization: Basis International, Albuquerque, NM Lines: 24 In article <352@yetti.UUCP> asst-jos@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