delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/11/08/14:34:42

From: Robert Neinast <neinast AT worldnet DOT att DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Can't Even Read File Correctly
Message-ID: <MPG.1654a7511c522106989691@netnews.worldnet.att.net>
References: <MPG DOT 165491792e225e13989690 AT netnews DOT worldnet DOT att DOT net> <9sei6v$8j9$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE>
X-Newsreader: MicroPlanet Gravity v2.50
Lines: 38
Date: Thu, 08 Nov 2001 19:28:29 GMT
NNTP-Posting-Host: 12.87.146.53
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc05-news.ops.worldnet.att.net 1005247709 12.87.146.53 (Thu, 08 Nov 2001 19:28:29 GMT)
NNTP-Posting-Date: Thu, 08 Nov 2001 19:28:29 GMT
Organization: AT&T Worldnet
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <9sei6v$8j9$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE>, broeker AT physik DOT rwth-
aachen.de says...
> Robert Neinast <neinast AT worldnet DOT att DOT net> wrote:
> 
> > This is driving me nuts.  In C, I'm doing simple getchars from
> > stdin and writing to a file, and it keeps getting truncated.
> > Anybody have any ideas what the heck I'm doing wrong????
> 
> In DOS, text files have a different line end ("\r\n" instead of a
> simple "\n", in C terms), and Ctrl-Z is interpreted as an end-of-file
> marker.  Stdin is opened in *text* mode, by default.
> 
> To get around this, you have to set the file handling mode of stdin to
> binary:
> 
> 	setmode(fileno(stdin), O_BINARY);
> 
> See the docs on these functions for details.

OK, I was right on the verge.  My original had it reading
from a file, which I opened with fopen(filename, "r").
Then in trying to isolate the problem, I converted to stdin
and still had the problem.  Then (I know, wrong order) I
read the docs and for some silly reason modified
my *write* open to fopen(filename, "w") to fopen(filename, "wb").

So, I was on the right trail; just not thinking hard enough.

Any way to change EOF to ctrl-D like real UNIX (and to reset
interrupt)?  I notice that there is no bash command like stty.

Many thanks for the assistance.

Bob
-- 
. . . and shun the Frumious Bandersnatch
Robert A. Neinast
Pickerington, OH

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019