Catching ^C and ^Z

Lars Poulsen lars at spectrum.CMC.COM
Fri Sep 7 04:35:49 AEST 1990


In article <Sep.4.20.08.17.1990.1216 at utopia.rutgers.edu> deen at utopia.rutgers.edu (Cinnamon Raisin) writes:
>	The following is a short programme I wrote to test this out, 
>	but it dumps on me, and I don't know why.
>------------
>
>#include <stdio.h>
>#include <sys/ioctl.h>
>#include <sgtty.h>
>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);
>}

The ioctl() functions move data between internal places in the system
and a structure of type "struct sgttyb" in your program. You have
created a variable to hold a pointer to such a structure, but you have
never created a structure to actually hold the data, and your pointer
has never been initialized.

The following changes should cure the problem:
	struct sgttyb TTY;
	  ioctl(0,TIOCGETP,&TTY);	/* Get current status	  */


-- 
/ Lars Poulsen, SMTS Software Engineer
  CMC Rockwell  lars at CMC.COM



More information about the Comp.lang.c mailing list