From: Hans-Bernhard Broeker 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: 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 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.