函数名: fclose
功 能: 关闭一个流。注意:使用fclose函数就可以把缓冲区内最后剩余的数据输出到磁盘文件中,并释放文件指针和有关的缓冲区。
用 法: int fclose(FILE *stream);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
FILE *fp;
char buf[11] = "0123456789";
/* create a file containing 10 bytes */
fp = fopen("DUMMY.FIL", "w");
fwrite(&buf, strlen(buf), 1, fp);
/* close the file */
fclose(fp);
return 0;
}
如果流成功关闭,fclose 返回 0,否则返回EOF(-1)。
如果流为NULL,而且程序可以继续执行,fclose设定error number给EINVAL,并返回EOF。