定義和用法
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。