delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/09/18:57:15

Newsgroups: comp.os.msdos.djgpp
From: design AT netcom DOT com (Chris Waters)
Subject: Re: Trouble with getche()
Message-ID: <designDz110r.6GC@netcom.com>
Organization: Design and Delivery
References: <325B1E56 DOT 5BDA AT erols DOT com>
Date: Wed, 9 Oct 1996 21:00:27 GMT
Lines: 22
Sender: design AT netcom4 DOT netcom DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <325B1E56 DOT 5BDA AT erols DOT com>, Tony Sideris  <tonys111 AT erols DOT com> wrote:
>I'm trying to do this simple little C thing, but it won't work right...I
>copied it right out of a C book.
>Here's what I type:
>main()
>{
> char ch;
> printf("Type a character: ");
> ch = getche();
> printf("\nYou typed: %c", ch);
>}

Your book sucks.  First of all, does it *really* not mention include
files?  There is no guarantee that *either* getche() or printf() will
work unless you include the appropriate headers.  Second, does it
mention that getche() is a non-standard extension?  I didn't think so.
So it's no surprise that it doesn't discuss buffered versus unbuffered
i/o.  Several other people have described how to fix this code; my
suggestion is to look for a better book while you're at it.  (I
recommend _The C Programming Language_ by Kernighan and Richie; others
may have recommendations for books that cover specifics of common
non-standard extensions for DOS like getche() and such.)

- Raw text -


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