Echoing chars and input functions

The Beach Bum jfh at rpp386.UUCP
Fri Aug 19 09:05:03 AEST 1988


In article <2821 at boulder.Colorado.EDU> swarbric at tramp.Colorado.EDU (Frank Swarbrick) writes:
>In article <8349 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>>In article <8808160751.aa03016 at SMOKE.BRL.MIL> dsill at NSWC-OAS.ARPA (Dave Sill) writes:
>>>What, then, is the portable way to input a character from standard input,
>>>echoing the character to the screen when necessary?
>>
>>We already answered that!  It's
>>	c = getchar();
>
>I could have sworn someone said their compiler did not echo the character when
>they used this.  Did I misunderstand someone, or is their compiler just
>non-conformant (broken)?

perhaps what needs to be said is that getchar() does not echo characters.
the operating system does.  if ms-dos does not perform character echoing
when reading from the keyboard, then this becomes an operating system
issue, not a language one.  likewise for all operating systems which C
is used on.  the description for getchar() is "read a character from
standard input".

a portable way to do "echoing" would be

	(c = getchar ()) != EOF && putchar (c);

this explicitly echoes the characters.  it is also "broken" on unix.
-- 
John F. Haugh II                 +--------- Cute Chocolate Quote ---------
HASA, "S" Division               | "USENET should not be confused with
UUCP:   killer!rpp386!jfh        |  something that matters, like CHOCOLATE"
DOMAIN: jfh at rpp386.uucp          |         -- apologizes to Dennis O'Connor



More information about the Comp.lang.c mailing list