Path: utzoo!attcan!uunet!lll-winken!ames!haven!purdue!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: What is wrong? Message-ID: <401@lakart.UUCP> Date: 25 Jan 89 21:44:10 GMT References: <2051@ndsuvax.UUCP> Distribution: na Organization: Lakart Corporation, Newton, MA Lines: 21 From article <2051@ndsuvax.UUCP>, by numork@ndsuvax.UUCP (James Mork): > I am using TC 1.5 everything was going OK... Now... when I run > 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? Is this just some error that > I am staring at, or is my compiler in foo bar land? The infamous MS-DOS (and CP/M) end of file problem. 26 is the magic number. Early DOS programs and ALL CP/M programs that deal with text files do so in complete blocks: 128 bytes at a time. So how do you deal with a text file 20 characters long? Easy: put the 20 characters in, and fill the rest of the block with 0x1a. This means that anyone reading the file _IN TEXT MODE_ will see the first 0x1a as an end of file. In particular your putc(26, fp); will put an EOF in a text file. NOW try doing the same with the files open in binary mode (r+ or rb or whatever it is), and you may have somewhat better luck. -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+