Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!charyb!will From: will@kfw.COM (Will Crowder) Newsgroups: comp.lang.c Subject: Re: Catching ^C and ^Z Message-ID: <1990Sep5.173015.12072@kfw.COM> Date: 5 Sep 90 17:30:15 GMT References: Reply-To: will@kfw.com (Will Crowder) Organization: KFW Corporation, Newbury Park, CA Lines: 48 In article deen@utopia.rutgers.edu (Cinnamon Raisin) writes: > >Hi boys and girls, >[I want a lockscreen program] > The following is a short programme I wrote to test this out, > but it dumps on me, and I don't know why. > > >------------ > >#include >#include >#include >char TMP; /* to hold keyboard entry */ >struct sgttyb *TTY; /* From unix ref */ > >int main(void) >{ > ioctl(0,TIOCGETP,TTY); /* Get current status */ > TTY->sg_flags = RAW | ECHO; /* Unprocessed and echoed */ > ioctl(0,TIOCSETN,TTY); /* to the screen */ > while(1 == 1) {TMP = getchar();} > exit(0); >} You're calling ioctl() with a pointer to garbage, namely, TTY. This ioctl() wants a pointer to the structure to be read from/filled in, but this structure must be defined somewhere. Change struct sgttyb *TTY; to struct sgttyb TTY; and change both of your ioctl() calls to use &TTY instead of just TTY, and things should be happy. Oh, and for complete portability and correctness, cast the &TTY to a char * or caddr_t or whatever your particular ioctl() wants. (man ioctl) Oh, and yeah, you don't need that TMP variable. Just call getchar() or whatever. C will throw away the return value. If you want lint to be quiet about it, say (void) getchar(). Will P.S. The 1 == 1 in your while statement is unnecessary. Use while (1) or for (;;). The latter is considered by many to be superior, because many older compilers generate better code for it. (The reason for that is too lengthy to go into in this article.)