Groovy hepcat Ming Pan was jivin' on Fri, 9 Oct 1998 17:30:28 -0500 in
comp.lang.c.
scanf() skipped's a cool scene! Dig it!
Quote:
>I have a program that uses scanf() to get some inputs interactively.
Is this another joke post or a troll? (It's hard to tell sometimes.)
If it is, then just ignore my explanation and slight rant. If not, pay
attention.
Quote:
>the first several scanf()'s ran fine, the program went on to process
>some of the inputs, printed out something to the standard output, then
>scanf()'s were called again to get some more inputs. but this time, the
>cursor didn't wait for the user to enter data any more, instead, the
>program just blasted thru all the new scanf()'s.
If you had the manners to read the group for a while, and read the
FAQ, - before posting - then you would know that scanf() is a bad
function. Its use is frought with toils and troubles.
Quote:
>what went wrong? standard input was never closed. I encountered
scanf() will leave a newline in the input stream, thus skipping
input on the next call since it cannot read past the newline.
Quote:
>the same kind of problems before in college, but really can't remember
>what the problem was and its fix.
Don't use scanf(). Do read the FAQ. Do read this group for a while
before posting a question, in case someone else has already asked it.
Do use fgets() to read a line of input (including the newline), then
scan with sscanf(). Do read the FAQ. Do read this group for a while
before posting a question, in case someone else has already asked it.
Do read the FAQ. Do read this group for a while before posting a
question, in case someone else has already asked it. (Yes, I do know
I've repeated myself. I did that deliberately, so you'd get the
picture in no uncertain terms.)
--
----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----
-------------- Shaggy was here! ---------------
http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============