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

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Can't Even Read File Correctly
Date: 8 Nov 2001 18:17:03 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 19
Message-ID: <9sei6v$8j9$1@nets3.rz.RWTH-Aachen.DE>
References: <MPG DOT 165491792e225e13989690 AT netnews DOT worldnet DOT att DOT net>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 1005243423 8809 137.226.32.75 (8 Nov 2001 18:17:03 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 8 Nov 2001 18:17:03 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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.
-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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