fclose - C stdio.h

C examples for stdio.h:fclose

Type

function

From


<cstdio>
<stdio.h>

Prototype

int fclose ( FILE * stream );

Description

Closes the file. All internal buffers for the stream are disassociated from it and flushed.

Parameters

Parameter Description
stream Pointer to a FILE object that specifies the stream to be closed.

Return Value

If the stream is successfully closed, a zero value is returned. On failure, EOF is returned.

Example

This following code creates a new text file, then writes a sentence to it, and then closes it.

Demo Code

#include <stdio.h>

int main (){/*from  w ww  .j  a v a  2  s  .c  o m*/
  FILE * pFile;
  pFile = fopen ("main.cpp","wt");

  fprintf (pFile, "test");

  fclose (pFile);
  return 0;
}

Related Tutorials