_fcloseall -- Close All Open Streams

Format

#include <stdio.h>
int _fcloseall(void);

Language Level: Extension
_fcloseall closes all open streams, except stdin, stdout, and stderr. It also closes and deletes any temporary files created by tmpfile.

_fcloseall flushes all buffers associated with the streams before closing them. When it closes streams, it releases the buffers that the system reserved, but does not release user-allocated buffers.

Return Value
_fcloseall returns the total number of streams closed, or EOF if an error occurs.

Example
This example opens a file john for reading as a data stream, and then closes the file. It closes all other streams except stdin, stdout, and stderr.

#include <stdio.h>
#define OUTFILE "temp.out"
int main(void)
{
   FILE *stream;
   int numclosed;
   stream = fopen(OUTFILE, "w");
   numclosed = _fcloseall();
   printf("Number of files closed = %d\n", numclosed);
   remove(OUTFILE);
   return 0;
   /***************************************************
      The output should be:
      Number of files closed = 1
   ***************************************************/
}



close -- Close File Associated with Handle
fclose -- Close Stream
fflush -- Write Buffer to File
fopen -- Open Files
freopen -- Redirect Open Files
tmpfile -- Create Temporary File
<stdio.h>