Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!mailrus!iuvax!bobmon From: bobmon@iuvax.cs.indiana.edu (RAMontante) Newsgroups: comp.lang.c Subject: Re: What is wrong? Message-ID: <16823@iuvax.cs.indiana.edu> Date: 25 Jan 89 03:37:58 GMT Reply-To: bobmon@iuvax.cs.indiana.edu (RAMontante) Organization: malkaryotic Lines: 22 <9492@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ): >In article <2051@ndsuvax.UUCP> numork@ndsuvax.UUCP (James Mork) writes: [ a living testament to the desirability of whitespace... ] >- j=putc(i,fi); >- a simple program like this, the file gets truncated after 25 or >- 26 bytes... After 25 when I read the file back in, I just >- get EOF (-1). What is wrong? > >Sounds to me like a ^Z in a text stream is taken as an EOF indicator. >I know CP/M had this misfeature; maybe PC-DOS does too. MSDOS has exactly this feature; and it is an inheritance from CP/M. BTW, the file may actually have all 200 values in it. Any debugger or hex-lister program could show the actual contents. But the test program will see the 27th byte, which is numbered 26, as the end-of-file character. >You probably should have been using binary streams instead. >I.e. fopen with mode "wb" or "rb". Or (in Turbo C) set the external global variable "_fmode" equal to "O_BINARY" as defined in fcntl.h. This is described in the "fopen" section of the TurboC reference manual.