home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: MS-C fread bug
- Message-ID: <1992Sep4.151759.16735@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Sep3.141100.28778@wuecl.wustl.edu> <a_rubin.715550662@dn66>
- Date: Fri, 4 Sep 1992 15:17:59 GMT
- Lines: 27
-
- a_rubin@dsg4.dse.beckman.com (Arthur Rubin) writes:
-
- >In <1992Sep3.141100.28778@wuecl.wustl.edu> drm4005@wuee1.wustl.edu (David Russell Maffitt) writes:
-
- >>Here is a simple piece of code that does not work under MS-C versions ...
- >>What is magic about the value 70.689651??? ...
-
- >MAGIC has a byte which has the value 0x1A, which is processed as an end of
- >file by MS-DOS. If you open fp2 in mode "rb" instead of "r", there is no
- >problem.
-
- This deserves a bit of explanation.
-
- When you open a file with the "r" or "w" mode, you tell the C runtime
- library, and thus the file system, that you are reading or writing
- a text file. If you then read or write binary data, you may well
- get bizarre results. Maffitt found one such. There are other things
- which can happen, such as mapping to and from what appear to be CR-LF
- sequences but which are intended to be just binary bytes of data.
-
- When you input and ouput binary data, you need to tell the runtime
- system that you want a binary rather than a text file. The "rb"
- and "wb" in the mode parameter to the "fopen" function do just that.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-