Re: how to check the scanf function if it will read more than one number



Moosdau said:

>
> Richard Heathfield wrote:
>
>> For the same reason that pressing the handle on your toilet will not get
>> rid of the water waiting in your sink's tap (or faucet, if you're on that
>> side of the pond). Flushing is something we do to output, not to input.
>
> thanks.
> but what I want to know is the "actual" reason,
> not a "logical" one.

I gave you both in my previous reply; as well as the text you quote above, I
also wrote: "Because fflush's behaviour is only defined for streams open
for output or update." That is the actual reason.

> if p is a NULL pointer, p->num will cause the error.

The C Standard assures us the code is wrong to dereference a null pointer,
but it does not specify that there will be "an error". It only says the
behaviour is undefined.

> so ,the fflush function works very well on my computer now,

That's nice.

> If it cause a potential danger,

If you use it in a way it was never intended to be used, that's a potential
danger.

> I want to know what is it, and what is the condition.
> if possible, an example is the best. :)

Okay, here's an example. Let's say you choose to use fflush(stdin) because
Microsoft say it's okay, and then in five years time Microsoft goes bust
and everyone starts using Macs instead, and you port your code to a Mac and
suddenly it stops working, and the reason it stops working is that you
thought "MSDN" was an acceptable substitute for "The ISO C Standard" and
wrote your code on that basis. Well, if you want to create unnecessary
portability headaches for yourself, that's your lookout.

The irony is that this is such a pointless discussion, since you simply
don't /need/ to "flush" input. Well, I don't, anyway, and I do a /lot/ of
text processing in C.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: oscillator
    ... Richard Heathfield writes: ... Presumably for the same reason that we argue with trolls. ... every statement) is of course an utterly ludicrous position, ...
    (comp.lang.c)
  • Re: How to make C look like C++
    ... > Richard Heathfield wrote: ... >> All the more reason, IMHO, to give correct answers to the questions ... long song and dance about the Task Control Block, what was in it, how ... etc. (Try to quickly explain the TIOT to a ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Flame Bait! Windows vs: The Unices
    ... > Richard Heathfield wrote: ... >> I see no reason why the OS should suddenly take it upon itself to ... Richard claimed to be using the .doc extension prior to ...
    (comp.programming)
  • Re: C99 Question
    ... > Richard Heathfield wrote: ... > And, if so, does your employer/client know that you do that? ... completely rewritten when they decide they want to compile it as a Java ... in the common subset of C and C++ without a very good reason. ...
    (comp.lang.c)
  • Re: The Wintard Preoccupation with Price and Marketshare
    ... "You provided support when Macs were used as the ... is no reason to think even you believe your claims. ... You have claimed to disagree that similarly configured Macs ... When I talked about teaching "on OS X" you insisted I ...
    (comp.sys.mac.advocacy)