Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!ncar!tank!uxc!uxc.cso.uiuc.edu!uxg.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: printf, data presentation Message-ID: <225800107@uxe.cso.uiuc.edu> Date: 11 Jan 89 15:22:00 GMT References: <19@xenlink.UUCP> Lines: 44 Nf-ID: #R:xenlink.UUCP:19:uxe.cso.uiuc.edu:225800107:000:2270 Nf-From: uxe.cso.uiuc.edu!mcdonald Jan 11 09:22:00 1989 I said this: >> The important point is that some such function should be a >> STANDARD C (ANSI C) function, ... peter@ficc.uu.net replies: >You obviously didn't pay attention to me. I just got through saying that >INKEY$ is an extremely infeccient and CPU-intensive way of operating under >an operating system like UNIX. It should certainly not be made part of >'C', just because of this little inconvenient fact. Any time you want to >do INKEY$, stop and ask yourself what you're really doing. You may very >well find that there are better tools... available and portable. Look up >signal(), and meditate on multitasking. And I say that peter@ficc.uu.net doesn't know what he is talking about. I read from by Basic manual (I do that because I never use Basic. The equivalent function in Microsost C is if(kbhit())(if ((c1=getch()) == 0)c2=getch()).) that v$=INKEY$ returns one character read from the keyboard. If no character is pending in the keyboard buffer, a null string is returned. This implies that it does not wait for input, but rather returns at once. If there is something there, the program acts on it. If nothing is there, and the program is in the middle of doing something useful, like a compute-bound task, it continue computing. If it has nothing more to do at the moment, and needs input to continue, it THEN calls the function (getch() in MSC) which reads from the keyboard without echoing, and which WAITS for input. In a multitasking environment like Desqview or Windows, this yields to another process. To see an example of code with this in it, look in my TeX screen preview program dvivga (routines dvivga.c and prtpage.h) available by anonymous ftp from b.scs.uiuc.edu. I see not the tiniest reason that the functions kbhit() and getch() couldn't be implemented on any reasonable system, including Unix or VMS. I've even written a kbhit() for VMS (ugh! I'll bet Unix will be easier.) The problem on multitasking systems arises when more than one type of asymchronous event must be detected while waiting (such as both keyboard and mouse events.) Then the only general solution that works on both multitasking and normally non-multitasking systems is to call an operating system sleep() routine to wait a decent interval, then retest.