Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to check the scanf function if it will read more than one number

Reply
Thread Tools

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

 
 
Jordan Abel
Guest
Posts: n/a
 
      01-03-2006
On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
> 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?

> although I don't know why you would bother.

 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=
Guest
Posts: n/a
 
      01-03-2006
Jordan Abel <(E-Mail Removed)> writes:
> On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
> > #define flushstdin flushln(stdin)

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


Read before answering.

DES
--
Dag-Erling Smørgrav - http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Chuck F.
Guest
Posts: n/a
 
      01-03-2006
Jordan Abel wrote:
> On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
>
>> 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?
>
>> although I don't know why you would bother.


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/>
 
Reply With Quote
 
pemo
Guest
Posts: n/a
 
      01-03-2006

"Chuck F. " <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Jordan Abel wrote:
>> On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
> >
>>> 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?
>>
>>> although I don't know why you would bother.

>
> 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 *****


 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-03-2006
Chuck F. said:

> Jordan Abel wrote:
>> On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
> >
>>> 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?
>>
>>> although I don't know why you would bother.

>
> 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..."

--
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)
 
Reply With Quote
 
Chuck F.
Guest
Posts: n/a
 
      01-03-2006
Richard Heathfield wrote:
> Chuck F. said:
>> Jordan Abel wrote:
>>> On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
>>>
>>>> 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?
>>>
>>>
>>>> although I don't know why you would bother.

>>
>> 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..."
>

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/>
 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      01-03-2006
Moosdau wrote
(in article
<(E-Mail Removed) .com>):

>
> 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 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?




--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw





 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      01-03-2006
Moosdau wrote
(in article
<(E-Mail Removed). com>):

> 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.


--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw





 
Reply With Quote
 
Jordan Abel
Guest
Posts: n/a
 
      01-03-2006
On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
> Richard Heathfield wrote:
>> Chuck F. said:
>>> Jordan Abel wrote:
>>>> On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
>>>>
>>>>> 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?
>>>>
>>>>
>>>>> although I don't know why you would bother.
>>>
>>> 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..."
>>

> 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.
 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      01-03-2006
Jordan Abel wrote
(in article <(E-Mail Removed)>):

> On 2006-01-03, Chuck F. <(E-Mail Removed)> wrote:
>> 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?


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.


--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Can one declare more than one signal on one line? Merciadri Luca VHDL 4 11-01-2010 02:00 PM
difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005? =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 18 05-02-2006 10:53 AM
scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc. =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 185 04-03-2006 02:49 PM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net 2 07-02-2004 10:35 AM



Advertisments