- 论坛徽章:
- 0
|
请教函数fflush
对,我也发现
#include <stdio.h>;
#include <conio.h>;
void main( void )
{
int integer;
char string[81];
string[0]='y';
string[1]='z';
/* Read each word as a string. */
printf( "Enter a sentence of four words with scanf: " );
for( integer = 0; integer < 4; integer++ )
{
scanf( "%s", string );
printf( "%s\n", string );
}
/* You must flush the input buffer before using gets. */
fflush( stdin );
printf( "Enter the same sentence with gets: " );
gets(string);
printf( "%s %c\n", string ,string[1]);
}
#include <stdio.h>;
#include <conio.h>;
void main( void )
{
int integer;
char string[81];
string[0]='y';
string[1]='z';
/* Read each word as a string. */
printf( "Enter a sentence of four words with scanf: " );
for( integer = 0; integer < 4; integer++ )
{
scanf( "%s", string );
printf( "%s\n", string );
}
/* You must flush the input buffer before using gets. */
//fflush( stdin );
printf( "Enter the same sentence with gets: " );
//gets(string);
scanf( "%s", string );
printf( "%s %c\n", string ,string[1]);
}
这两个程序输出一样,而#include <stdio.h>;
#include <conio.h>;
void main( void )
{
int integer;
char string[81];
string[0]='y';
string[1]='z';
/* Read each word as a string. */
printf( "Enter a sentence of four words with scanf: " );
for( integer = 0; integer < 4; integer++ )
{
scanf( "%s", string );
printf( "%s\n", string );
}
/* You must flush the input buffer before using gets. */
//fflush( stdin );
printf( "Enter the same sentence with gets: " );
gets(string);
// scanf( "%s", string );
printf( "%s %c\n", string ,string[1]);
}
就不一样了,我还是不懂??
这里还牵扯到scanf与gets的区别吧 |
|