delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/03/17:51:56

Date: Wed, 3 Jul 1996 17:45:23 -0400 (EDT)
From: Justin Ward <justin AT yoss DOT canweb DOT net>
To: deuce <norbertj AT panix DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Cannot redirect getche()
In-Reply-To: <4re1a1$kg5@panix2.panix.com>
Message-ID: <Pine.BSF.3.91.960703174230.826A-100000@yoss.canweb.net>
MIME-Version: 1.0


On 3 Jul 1996, deuce wrote:

> In a test program using getche(), the echo to the screen could not 
> redirect to a file  as in   test >test.txt.  printf() works fine.

getch() and getche() read from the console (keyboard and screen), not 
from stdin. You can always redirect stdin and stdout, but the console is 
always (at least in DOS) the screen and the keyboard. Well unless you 
mess around with that command to read from a com port instead of the 
keyboard (can't remember the name right now), but that is not a common 
situation.

Anyway, there's no real way you can redirect getch() or getche(). If you 
want to read from stdin, use getchar(). Be warned though, stdin (and all 
streams) are read a line at a time. So to get one character, a whole line 
of input must be typed in.

Justin

- Raw text -


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