C语言中的fflush函数
来源:互联网 发布:淘宝服装店推广 编辑:程序博客网 时间:2024/05/18 04:00
Flushes a stream.
int fflush( FILE *stream );
Return Value
fflush returns 0 if the buffer was successfully flushed. The value 0 is also returned in cases in which the specified stream has no buffer or is open for reading only. A return value of EOF indicates an error.
Parameter
stream
Pointer to FILE structure
Remarks
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. fflush negates the effect of any prior call to ungetc against stream. Also, fflush(NULL) flushes all streams opened for output. The stream remains open after the call. fflush has no effect on an unbuffered stream.
Buffers are normally maintained by the operating system, which determines the optimal time to write the data automatically to disk: when a buffer is full, when a stream is closed, or when a program terminates normally without closing the stream. The commit-to-disk feature of the run-time library lets you ensure that critical data is written directly to disk rather than to the operating-system buffers. Without rewriting an existing program, you can enable this feature by linking the program’s object files with COMMODE.OBJ. In the resulting executable file, calls to _flushall write the contents of all buffers to disk. Only _flushall and fflush are affected by COMMODE.OBJ.
Example
/* FFLUSH.C */#include <stdio.h>#include <conio.h>void 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 ); 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\n", string );}
Output
Enter a sentence of four words with scanf: This is a testThisisatestEnter the same sentence with gets: This is a testThis is a test
- C语言中的fflush函数
- C语言中的fflush函数
- c 语言函数 fflush()
- C语言fflush()函数
- C语言中的清空输入缓冲区函数fflush()
- C语言函数随记:fflush()函数
- C语言中fflush函数的使用方法
- C语言中fflush函数的使用方法
- C语言中fflush函数的使用方法
- C语言fflush函数的移植问题
- C语言库函数 fflush
- C语言 -- fflush()
- C语言 -- fflush()
- C fflush()函数
- C语言第十六篇:fflush函数有什么作用?
- C语言的scanf()函数用法详解 (缓冲区、格式控制、fflush)
- C语言fflush()函数:清空文件缓冲区(或标准输入输出缓冲区)
- C语言fflush()函数:清空文件缓冲区(或标准输入输出缓冲区)
- java获得项目绝对路径
- 编译 boost 的正则表达式部分
- 代码质量控制
- cocos2d:init和onEnter的区别
- 使用scp在windows和Linux之间互传文件
- C语言中的fflush函数
- css 设置字体粗细font-weight:bold;
- nginx源码分析—内存池结构ngx_pool_t及内存管理
- oracle11 客户端安装及PLSQL和TOAD中文乱码
- iPhone应用程序开发基础之一: IBOutlet与IBAction
- ios开发中类方法以及self的注意点
- 第十三周任务(二)
- 使用 live555 直播来自 v4l2 的摄像头图像
- MyEclipse 设置JSP的默认打开方式