Re: how to check the scanf function if it will read more than one number
- From: "Moosdau" <moosdau@xxxxxxxxx>
- Date: 2 Jan 2006 21:33:56 -0800
Peter Nilsson wrote:
> 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.
>
it do be that.
I think I've already known the answer.
the below is I copied from MSDN:
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.
Example
// crt_fflush.c
#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 );
}
Input
This is a test
This is a test
Sample Output
Enter a sentence of four words with scanf: This is a test
This
is
a
test
Enter the same sentence with gets: This is a test
This is a test
then I know,I shouldn't use fflush(stdin) except in VC.
but in VC, it is safe.
thanks to all again !
.
- Follow-Ups:
- Re: how to check the scanf function if it will read more than one number
- From: Randy Howard
- Re: how to check the scanf function if it will read more than one number
- From: Chuck F.
- 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
- 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
- Re: how to check the scanf function if it will read more than one number
- From: Peter Nilsson
- how to check the scanf function if it will read more than one number
- Prev by Date: Segmentation fault - interesting problem with array
- Next by Date: Re: Segmentation fault - interesting problem with array
- 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
|