What is wrong?
Mark A. Charette
charette at edsews.EDS.COM
Wed Jan 25 22:47:38 AEST 1989
In article <9492 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn ) writes:
> In article <2051 at ndsuvax.UUCP> numork at ndsuvax.UUCP (James Mork) writes:
>> - 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.
>
> You probably should have been using binary streams instead.
> I.e. fopen with mode "wb" or "rb".
PC/MS-DOS definately DOES have this misfeature. The "wb" / "rb" 'fix' as
suggested by Mr. Gwyn will solve the problem (I tested at home).
If a program does not have to access any files outside of it's own
requirements, the use of binary modes will save a lot of headaches for PC
programmers. In MS C, the default mode can be changes to binary, with the
resulting CR/LF translation problems and ^Z EOF marker 'fixed'.
--
Mark Charette "People only like me when I'm dumb!", he said.
Electronic Data Systems "I like you a lot." was the reply.
750 Tower Drive Voice: (313)265-7006 FAX: (313)265-5770
Troy, MI 48007-7019 charette at edsews.eds.com uunet!edsews!charette
More information about the Comp.lang.c
mailing list