|
发表于 2004-12-7 21:29:23
|
显示全部楼层
程序可能是没有问题, 或者你在最后显示的printf中加一个换行符'\n'试试,
应该就可以显示了。
当然用fflush(stdout)是没错的。
fflush(stdout) 的作用:
把输入缓冲区的内容清空,或者把输出缓冲区的内容输出到stream中,
stream可以是文件,也可以是stdout, 标准输出终端(屏幕)
google 一下, 到处都是详细解释
fflush
<stdio.h>
int fflush (FILE * stream);
Flush a stream.
If the given stream has been opened for writing operations the output buffer is phisically written to the file.
If the stream was open for reading operations the content of the input buffer is cleared.
The stream remains open after this call.
When a file is closed all the buffers associated with it are automatically flushed. If the program terminates, every buffer is automatically flushed.
Parameters.
stream
pointer to an open file.
Return Value.
A 0 value indicates success.
If any errors occur, EOF is returned.
Example.
To demonstrate the use of fflush, we ask twice the user to input some words in a sentence. Each time the program reads the first word with scanf and flushes the rest. The next time the user is prompt the buffer will be cleared so we will be able to obtain the first word of the new sentence.
/* fflush example */
#include <stdio.h>
int main()
{
int n;
char string[80];
for ( n=0 ; n<2 ; n++ )
{
printf( "Enter some words: " );
scanf( "%s", string );
printf( "The first word you entered is : %s\n", string );
fflush ( stdin );
}
return 0;
}
Output.
Enter some words: Testing this program
The first word you entered is : Testing
Enter some words: It seems to work...
The first word you entered is : It |
|