fclose function closes a file and flush its buffer

Syntax

C fclose function has the following syntax.

int fclose(FILE *stream);

C fclose function is from stdio.h.

Description

C fclose function closes the file and flushes its buffer.

Trying to close a file that has already been closed is an error. If successful, zero is returned, or EOF is returned.

Example

Use C fclose function to close a file and flush buffer.


#include <stdio.h>
#include <stdlib.h>
// w  w w.ja  v a  2s .  c om
int main(void)
{
  FILE *fp;

  if((fp=fopen("test", "rb"))==NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }

  if(fclose(fp))
      printf("File close error.\n");

  return 0;
}




















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h