Re: how to check the scanf function if it will read more than one number
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Tue, 3 Jan 2006 07:41:00 +0000 (UTC)
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)
.
- Follow-Ups:
- References:
- how to check the scanf function if it will read more than one number
- From: moosdau
- Re: how to check the scanf function if it will read more than one number
- From: Keith Thompson
- Re: how to check the scanf function if it will read more than one number
- From: moosdau
- Re: how to check the scanf function if it will read more than one number
- From: Richard Heathfield
- Re: how to check the scanf function if it will read more than one number
- From: Moosdau
- how to check the scanf function if it will read more than one number
- Prev by Date: Re: how to check the scanf function if it will read more than one number
- Next by Date: Re: thread problem...
- Previous by thread: Re: how to check the scanf function if it will read more than one number
- Next by thread: Re: how to check the scanf function if it will read more than one number
- Index(es):
Relevant Pages
|