single character input

Kral braun at drivax.UUCP
Fri May 20 03:27:11 AEST 1988


Before everyone thinks I'm a total blockhead...

Someone, whose id I was clever enough to delete, wrote in response to my
original question:

: 
: Quickest way is to use gets() to grab a whole line of input at once.
: You only care what the first character is, right?  So only look at that
: and ignore the rest.
: 

And this is what I ended up doing.  It *is* rather obvious, isn't it?  I just
drew a total blank, mostly because of what I consider to be rather odd
behaviour on the part of scanf.  For instance, if I do the following:

	char	c ;


	puts(prompt) ;
	scanf("%c ", c) ;
	switch(c)
	{
	:
	}

The program ends up reading one line behind what is input; in other words, I
have to enter something (anything!) the first time, then the second line
entered triggers the program reading the first line, etc.  Not at all what I
expected, and it seems not too useful to me.  I got so hung up on scanf that
I couldn't think of anything else.  I wonder why scanf does this?  Am I missing
something equally obvious here?

So the question was really a scanf problem (although I really thought there
would have been an existing library routine to do what I wanted).

So, nevermind.


-- 
kral 	408/647-6112			...{ism780|amdahl}!drivax!braun
"I'll let you be in my dream                      If I can be in yours"
DISCLAIMER: If DRI knew I was saying this stuff, they would shut me d~-~oxx



More information about the Comp.lang.c mailing list