User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed



#include <stdio.h> /* including standard library */
    int fclose( FILE *stream );


Close the current stream / file
Used to close the specified file (stream). You should always use this function, to clean up after using a file.
Any data that has been written to the file, but not actually made it that far yet, i.e. which has only been written to the file buffer in memory,
will then be actually written to the physical file itself by the operating system.
The space in memory allocated for these buffers will also be deallocated. Any user defined buffers (specified by setbuf and setvbuf will however, not be deallocated.
Any temp files associated with the stream will also be deleted.

Returns EOF on error, zero otherwise.

C Sourcecode Example

 * fclose example code
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
int main( void )
  FILE *handle;
  handle = fopen("test.txt","r");
  if ( handle != 0 )
    printf("fopen success:\n");
  } else {
         printf("fopen failure\n");
         if (handle != NULL) {
         return 1;
  return 0;

fclose output

  output: if no test.txt file there
  user@host:~$ ./fclose 
  fopen failure
  output: if test.txt exist
  user@host:~$ ./fclose 
  fopen success

see also

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/fclose.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz