Mail Archives: djgpp/1996/10/09/18:57:15
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 -