fclose

Syntax

int fclose(int filepointer)

Arguments

filepointer
A pointer to a file/stream previously opened with fopen.

Return

Returns 0 if the file is closed successfully, and EOF if it encounters any problems.

Description

Closes a file or stream, writing any data remaining in the writing buffer to the file and freeing the file for use by other programs.

Example

int IMG_FILE;
if (IMG_FILE=fopen("d:\\FM_image0.fmi", "wb"))
{
  // Write out the src pixels as raw data
  for (z=0; z<Z; z++)
  for (y=0; y<Y; y++)
  for (x=0; x<X; x++)
    fputc(src(x,y,z), IMG_FILE);
}
else
  ErrorOk("Cannot write image file\nDrive is either full or write-protected!");

if (fclose(IMG_FILE))
  ErrorOk("Cannot close image file!");

Also see

fopen, fcloseall

Comments

Everyone can add his comments about his experiences with this function here. Tips for using it are welcome, too.