Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!crdgw1!nieters From: nieters@eagle.crd.ge.com (coolbean) Newsgroups: comp.unix.questions Subject: Re: Help, single char input Message-ID: Date: 18 Oct 90 19:10:09 GMT References: <1360@ul-cs.ulowell.edu> Sender: news@crdgw1.crd.ge.com Reply-To: nieters@crd.ge.com Organization: GE Corporate R&D, Schenectady, NY Lines: 80 In-reply-to: mchetan@hawk.ulowell.edu's message of 18 Oct 90 15:49:41 GMT hi there A readchar() program to suit your needs follows. I wasn't sure what version OS you were working on so I wrote a version to work on Sun OS 3.5 and one to work on Sun OS 4.0. A sample main() is included too. hope this helps. --ed -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= main() { int x; printf("enter a character: "); x = readchar(); printf("\nthe letter %c was entered.\n", x); } >>>>> Sun OS 3.5 Version: <<<<< #include #include int readchar() { struct sgttyb old, new; int x; ioctl(0, TIOCGETP, &old); /* get the current tty settings */ new = old; new.sg_flags |= CBREAK; ioctl(0, TIOCSETP, &new); /* set the new tty options */ x=getchar(); ioctl(0, TIOCSETP, &old); /* return the tty to its original state */ return(x); } >>>>> Sun OS 4.0 Version: <<<<< #include #include #include int readchar() { struct termios old, new; int x; ioctl(0, TCGETS, &old); /* get the current tty settings */ new=old; new.c_lflag &= ~ICANON; new.c_cc[VMIN]=1; new.c_cc[VTIME]=0; ioctl(0, TCSETS, &new); /* set the new tty options */ x=getchar(); ioctl(0, TCSETS, &old); /* return the tty to its original state */ return(x); } -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Ed Nieters INTERnet: nieters@crd.ge.com GE Corporate R&D UUCPnet: uunet!crd.ge.com!nieters Schenectady, NY 12301 BELLnet: (518) 387-5187