Mail Archives: djgpp/1998/05/07/08:17:52
#include <termio.h>
#include <sys/ioctl.h>
int getch() {
struct termio o, n;
char c;
ioctl(0, TCGETA, &o);
ioctl(0, TCGETA, &n);
n.c_lflag &= ~(ICANON | ECHO);
n.c_cc[VMIN] = 1;
n.c_cc[VTIME]= 0;
ioctl(0, TCSETA, &n);
while(read(0, &c, 1) <= 0);
ioctl(0, TCSETA, &o);
return (int)c;
}
Ville Lundberg wrote:
> I'm putting up a server and writing a program to it that asks for an
> password. I first wrote the program at home with DJGPP to DOS, and
> thought it would compile in UNIX. But it didn't, and I found out that it
> was because UNIX hasn't GETCH() as DOS does.
> So could anyone show me how to write that little piece of code that ask
> for the password WITHOUT echoing it to screen? I mean, a password that
> anyone can see by lookin over the shoulder is quite useless, isn't it?
> ;-) Thanks,
> --Ville
>
> =-----=
> 51) Pelimiehet ei tee virheitä.
> Ville Lundberg vlundber AT cc DOT hut DOT fi www.hut.fi/~vlundber/pelimiehet
> -----=
- Raw text -