fclose

close a file

Synopsis:

#include <stdio.h>
int fclose( FILE *fp );

Description:

The fclose() function closes the file fp. If there is any unwritten buffered data for the file, it is written out before the file is closed. Any unread buffered data is discarded. If the associated buffer was automatically allocated, it is deallocated.

Returns:

0
Success
non-zero
An error occurred. errno is set to indicate the error.

See also:

errno, fcloseall(), fdopen(), fopen(), freopen(), _fsopen()

Examples:

#include <stdio.h>

void main()
  {
    FILE *fp;

    fp = fopen( "stdio.h", "r" );
    if( fp != NULL ) {
      fclose( fp );
    }
  }

Classification:

ANSI

Systems:

All (except DOS/PM)