Re: how to check the scanf function if it will read more than one number
- From: "Peter Nilsson" <airia@xxxxxxxxxxx>
- Date: 2 Jan 2006 21:00:36 -0800
Moosdau wrote:
> 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.
The "actual" reason is that the C language standard does not define
a behaviour for fflush() on an input stream.
> e.g.
> void f( int*p )
> {
> if (p->num)
> do something;
> }
> when this function is running, there will be an error.
> if I don't know the reason,what I want to know is :
> if p is a NULL pointer, p->num will cause the error.
>
> so ,the fflush function works very well on my computer now,
Your implementation probably defines a behaviour fflush on
input streams. It would do so as an extension. That extension
is not topical in comp.lang.c.
> If it cause a potential danger,
> I want to know what is it, and what is the condition.
> if possible, an example is the best. :)
void g(FILE *fp)
{
fflush(fp);
}
If fp is purely an input stream, this invokes undefined behaviour. In
other
words, it's as dangerous as f() above.
--
Peter
.
- 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
|
|