定义和用法
fclose() 函数关闭一个打开文件。
语法
fclose(file)n
参数t描述
file必需。规定要关闭的文件。n
说明
file 参数是一个文件指针。fclose() 函数关闭该指针指向的文件。
如果成功则返回 true,否则返回 false。
文件指针必须有效,并且是通过 fopen() 或 fsockopen() 成功打开的。
程序例子
#include
#include
int main(void)
{
FILE *fp;
/* 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。