CompuServe Messages

C problems

    06-Mar-91 22:40:43
Sb: #8157-C problems
Fm: Greg Comeau@Comeau Cmptg 72331,3421
To: Robert Hayes 70431,1737
>you will find that now you have two "responses" every time you "enter" a >keystroke. The getchar() is not really suited to reading from the keyboard. Sorta… It is if you let it. Also, many C compiler do have strict console oriented I/O routines, whether this one does I do not know. >What now happens is that the correct choice he made is printed to screen >first, then the default choice is printed because getchar() also accepts and >sends his program the "enter" key (that is '\r', I believe). No. <enter> is a character in its own right, so there is not two responses, but two characters (I mentioned the fact that the original poster may have been hitting the <enter> key in my original reply to the message, but I do not believe that the poster has addressed this yet). >The programmer , would be better off defining a char string of 2 char long, >and just compare the first char in the string with the case statement. But then he wouldn't be doing getchar() but something like gets()'s. That would work if he only wanted to pull in the first character of every line. There are numerous other programmable alternatives as well.