What is wrong?

RAMontante bobmon at iuvax.cs.indiana.edu
Wed Jan 25 13:37:58 AEST 1989


<9492 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>):
>In article <2051 at ndsuvax.UUCP> numork at 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.



More information about the Comp.lang.c mailing list