fclose() – C库函数
C库函数int fclose(FILE *stream)关闭该流。所有的缓冲区被刷新。
声明
以下是声明fclose()函数。
int fclose(FILE *stream)
参数
-
stream -- 这是一个文件对象的指针指定的数据流被关闭。
返回值
此方法返回0,如果流成功关闭。如果失败,返回EOF。
例子
下面的例子演示了如何使用fclose()函数。
#include<stdio.h>int main(){ FILE *fp; fp = fopen("file.txt","w"); fprintf(fp,"%s","This is xyhtml5.com"); fclose(fp);return(0);}
让我们编译和运行上面的程序,这将创建一个文件file.txt的,第二个会写下面的文本行,最后它会使用 fclose()函数关闭文件。
This is xyhtml5.com