Help us and donate little Bitcoins to pay the server costs: 1AXLPuRUBYc1JczTW4XS65GL6oWjNP2Vt2

User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

because of the inhumane working conditions at amazon in Germany, I will offer the Amazon app no more! (ARD Reportage)


#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

c/stdio.h/fclose.txt · Last modified: 2013/01/22 22:02 (external edit)

The new Question & Answer System is online and waiting for your Questions about Programming problems Impressum