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

J

Jordan Abel

No, it doesn't handle EOF. However, if you have flushln available
you can write:

#define flushstdin flushln(stdin)

I've never heard of flushln - what systems does it exist on?
 
C

Chuck F.

Jordan said:
I've never heard of flushln - what systems does it exist on?

All you had to do was read this thread. I have published at least
two realizations of flushln in it.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
P

pemo

Chuck F. said:
All you had to do was read this thread. I have published at least two
realizations of flushln in it.

But, you know what's what here: if your comment doesn't appear with
[verbose] context, you're *****
 
R

Richard Heathfield

Chuck F. said:
All you had to do was read this thread. I have published at least
two realizations of flushln in it.

Usenet is an asynchronous medium. Please don't assume that everybody has
been able to read all previous articles in a thread. It is generally easy
to skip around this problem; for example, you could have said:

"However, if you use flushln() available on your system (source for the
fflushln function is provided upthread) you can write..."
 
C

Chuck F.

Richard said:
Chuck F. said:

Usenet is an asynchronous medium. Please don't assume that
everybody has been able to read all previous articles in a
thread. It is generally easy to skip around this problem; for
example, you could have said:

"However, if you use flushln() available on your system (source
for the fflushln function is provided upthread) you can
write..."
He's even more careless than that. One of the flushln
implementations was quoted in the article to which he replied, and
he snipped it! So there is no doubt he saw it.

Maybe he is one of the Wikipedia editors who are amusing you?

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
R

Randy Howard

Moosdau wrote
(in article
thanks.
but what I want to know is the "actual" reason,
not a "logical" one.

I think you will find that quite often (apart from understanding
the behavior of Wives and a few other exceptions) that the
"logical" one turns out to be the "actual" one.
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.

That is only one possible reason. There are other ways it could
fail, without a NULL pointer.
so ,the fflush function works very well on my computer now,
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. :)

Because the standard says so. Actual enough for you?
 
R

Randy Howard

Moosdau wrote
(in article
I think I've already known the answer.
the below is I copied from MSDN:

They should be ashamed.
The fflush function flushes a stream. If the file associated with
stream is open for output, fflush writes to that file the contents of
the buffer associated with the stream.
If the stream is open for input, fflush clears the contents of the
buffer.

Do they bother to point out that it is a non-standard extension
to have this behavior?

No?

Why not?

They want you to write non-portable code, it lends itself to
supporting their goal of monopoly.
#include <stdio.h>
#include <conio.h>

int main( void )
{
int integer;
char string[81];

/* Read each word as a string. */
printf( "Enter a sentence of four words with scanf: " );
for( integer = 0; integer < 4; integer++ )
{
scanf( "%s", string );
// Security caution!
// Beware allowing user to enter data directly into a buffer
// without checking for buffer overrun possiblity.
printf( "%s\n", string );
}

/* You must flush the input buffer before using gets. */
fflush( stdin ); // fflush on input stream is an extension to the
C standard
printf( "Enter the same sentence with gets: " );
gets( string );
printf( "%s\n", string );
}

This code is quite broken, for several reasons. Do you know
what they are?

The fact that MSDN includes bad code examples is hardly
surprising, considering the source (no pun intended).
then I know,I shouldn't use fflush(stdin) except in VC.
but in VC, it is safe.

Nothing about the above program is safe. Microsoft *claims*
that they are teaching their own programmers not to code this
way, yet it their examples still contain code which they are
*supposedly* not able to use themselves anymore. Think about
that before blinding following MSDN examples.
 
J

Jordan Abel

He's even more careless than that. One of the flushln
implementations was quoted in the article to which he replied, and
he snipped it! So there is no doubt he saw it.

Maybe he is one of the Wikipedia editors who are amusing you?

I didn't bother reading all the quoted text, and the text i did read
[and quote] said nothing to imply that it was a function you had written
in an earlier message - "if ___ is available on your system" implies (to
me) that it's a non-universally-available extension.
 
R

Randy Howard

Jordan Abel wrote
(in article said:
I've never heard of flushln - what systems does it exist on?

Source for it (looks pretty portable to me) was just posted
upthread. As such, it should be able to exist anywhere you want
it to, simply by using it.
 
R

Richard Heathfield

Chuck F. said:
One of the flushln
implementations was quoted in the article to which he replied, and
he snipped it! So there is no doubt he saw it.

Or at least, he had no business not seeing it and then complaining about it.
Fair enough, then - sorry for whinging at you inappropriately.
Maybe he is one of the Wikipedia editors who are amusing you?

I doubt it. Jordan does actually know his stuff, as far as I can tell.
 
K

Keith Thompson

Jordan Abel said:
[snip]
I didn't bother reading all the quoted text, and the text i did read
[and quote] said nothing to imply that it was a function you had written
in an earlier message - "if ___ is available on your system" implies (to
me) that it's a non-universally-available extension.

I made the same assumption. My first reaction to the phrase "if you
have flushln available" was to switch to a different window and type
"man flushln". I assumed it was something like strlcpy(); not part of
the C standard, but available as an extension on some systems.

Admittedly I wasn't following the thread all that closely, and once I
saw that it wasn't pre-installed I wasn't motivated to investigate
further. My point is merely that the misunderstanding that flushln
was a non-universally-available extension was a reasonable one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top