delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/11/16:34:27

Message-Id: <35D0AAC4.3C02@cableol.co.uk>
Date: Tue, 11 Aug 1998 21:34:12 +0100
From: Allens <allen DOT asjp AT cableol DOT co DOT uk>
Mime-Version: 1.0
To: Inkel AT sion DOT com
Cc: djgpp AT delorie DOT com
Subject: Re: getchar()
References: <0049b4557010b88PROXY AT sion DOT net>

Inkel AT sion DOT com wrote:
> 
> Hi, I think this is a little off-topic question, but anyway...
> 
> I'm reading K&R and, in the example 1.5 I have to use gecthar(), which
> should return _the pressed character_, and, redirect it to the screen
> with putchar(). Everything works fine except getchar, which only returns
> me the _single or multiple character stream_ I'm writing when I press
> <\n>. Why? Here is the code:
> 
> #define EOF    -1
> 
> main()
> {
>    int c;
> 
>    c = getchar();
>    while ( c != EOF)
>    {
>       putchar(c);
>       c = getchar();
>    }
> }
> 
> TIA
> 
> Leandro M. "Inkel" Lspez (mailto:inkel AT sion DOT com)
> Directly from Argentina. (Excuse my english)

getchar() is defined so the user has to press enter, so try #includeing 
<conio.h> and using getch instead, of getche if you do not want to have 
to echo the output to the screen.  (which insidently(?) is non ansi 
compliant, so don't use it if you want your code to be totally protable)
	As a last point, for general c related questions, comp.lang.c is 
probably the best place.

		Peter Allen

- Raw text -


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