Article View: comp.sys.ibm.pc
Article #41921Re: Password Entry Routines (Re: MS-DOS call to read without echo)
From: Tim Meighan
Date: Wed, 07 Feb 1990 23:34
Date: Wed, 07 Feb 1990 23:34
50 lines
2343 bytes
2343 bytes
In article <V&5S`+@rpi.edu> mcintyre@turing.cs.rpi.edu
(David McIntyre) writes:
> I sent Leo a response by email, but in case anyone else is wondering
> about this: MSC5.1 has a function called getch(), which gets a
> character from the console without echo.
getc() is part of the standard C library. getch() is a library function to
invoke getc() using standard input. Both of these should be available in all
commerical C compiliers. The getc() family does not echo characters.
kbhit() is NOT a standard C function. It is included with the MSC library.
It allows you to find out if there are any characters waiting in the keyboard
input buffer. This can be very helpful because if you call getch() and there
are no characters available from the source of input your program will hang
in the getch() routine until one is received.
An extra pitfall of IBM-PCs is that function keys return TWO characters,
not one. A call to getch() that returns a 0 indicates that there is another
character waiting. You can write a routine that makes a second call to getch()
under such circumstances to get the function key value. Adding a constant to
this second call will yield a value above the normal character return
values of 0 to 255, returning to you a single unique integer value regardless
of what key (if any) was pressed. Example:
/*
* GET_KEY() checks for IBM-PC keyboard input, returning a -1 if no character
* is available, 0 to 255 for regular keypresses, and values above 255 for
* function keypresses. Note that the function kbhit() is not from the
* standard library but is part of MSC. Use this function ONLY when
* standard input will be the PC keyboard.
*/
int get_key()
{
int c;
if(kbhit())
{
if((c = getch()) == 0)
{
c = (getch() + 197);
return(c);
}
}
return(-1);
}
Tim Meighan
Silent Radio
Technical Details
Message-ID:
<1262@srhqla.SR.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mailrus!iuvax!cica!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!srhqla!tcmShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mailrus!iuvax!cica!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!srhqla!tcm From: tcm@srhqla.SR.COM (Tim Meighan) Newsgroups: comp.sys.ibm.pc Subject: Re: Password Entry Routines (Re: MS-DOS call to read without echo) Message-ID: <1262@srhqla.SR.COM> Date: 7 Feb 90 23:34:14 GMT Reply-To: tcm@srhqla.SR.COM (Tim Meighan) Organization: Silent Radio, Los Angeles Lines: 50