CMP.DOUG@UTEXAS-20.ARPA (06/12/84)
From: Douglas Good <CMP.DOUG@UTEXAS-20.ARPA> I have started programming in C and have run into a few problems. First when I use the getchar statement it reads in characters until I type a return instead of one character. I have been using both C/80 and UNIX's C and the problem exists on both versions. Does anybody know what the best method for doing input is? I would also like to know how to send text to my printer and RS232 in C/80. Doug Good -------
jr@foros1.UUCP (John Rogers) (06/13/84)
Hi. The way you do character-at-a-time I/O with C/80 is described in section 9.1 of the manual (assuming you're using version 3.1): "In doing I/O to CON:, C/80 normally uses line at a time mode. This is true whether CON: has been accessed explicitly by opening file "CON:", or as the default device for getchar and putchar. If you need to use character at a time console I/O, set Cmode to zero. (It is initially set to 1; other values produce undefined results.)" Elsewhere, they declare Cmode as: extern char Cmode; This is all, of course, different from the way UNIX does things (which I assume everyone else will post answers about, so I won't bother). The same section of the C/80 manual talks about a few characters which C/80 traps, so you should definitely read it. I hope this helps. If you have any more questions, just ask... I'm working on a new library for C/80 (isn't everyone?), so I'm getting familiar with it, whether I like it or not. See ya! -- JR (John Rogers) ...ihnp4!fortune!foros1!jr also fortune!jr and proper!jr
dag@tellab2.UUCP (Donald Graft) (06/13/84)
The fact that getchar() is buffered on a line basis should not be considered a bug. The intent is to allow the user to edit data (by backspacing) before it reaches the program. If characters were returned when struck the program itself would need to provide any editing capabilities. Nevertheless, some applications require the immediate return of the character. To achieve this on unix, some ioctl calls can be made to reconfigure the tty. The program would then reset the tty before exiting. Under CP/M, perhaps the easiest way to achieve the desired result is to make a direct bdos call for input (in other words, don't use getchar()). I have used this technique for "hit any key when ready" situations.
mpackard@uok.UUCP (06/15/84)
Hello Douglas, Your problem appears to be lack of manuals! I'll pass some help though. Do this: extern char Cmode; main() { Cmode = 0; ... } This will give you character at a time input. for printers you might try: if ((fdp = fopen("LST:","w")) == 0) { error(); exit(); } ... putc(c,fdp); steve sampson Box 45668 Tinker AFB, OK 73145 uok!mpackard