### _flushall -- Write Buffers to Files

Format

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

Language Level: Extension
_flushall causes the system to write to file the contents of all buffers associated with open output streams (including stdout and stderr). It clears all buffers associated with open input streams of their current contents. The next read operation, if there is one, reads new data from the input files into the buffers. All streams remain open after the call.

For portability, use the ANSI/ISO function fflush instead of _flushall.

Return Value
_flushall returns the number of open streams of input and output. If an error occurs, _flushall returns EOF.

Example
In this example, _flushall completes any pending input or output on all streams by flushing all buffers.

    #include <stdio.h>

    int main(void)
    {
       int i,numflushed;
       char buffer1[5] =  { 1,2,3,4 };
       char buffer2[5] =  { 5,6,7,8 };
       char *file1 = "file1.dat";
       char *file2 = "file2.dat";
       FILE *stream1,*stream2;

       stream1 = fopen(file1, "a+");
       stream2 = fopen(file2, "a+");
       for (i = 0; i <= sizeof(buffer1); i++) {
          fputc(buffer1[i], stream1);
          fputc(buffer2[i], stream2);
       }
       numflushed = _flushall();                   /* all streams flushed */
       printf("Number of files flushed = %d\n", numflushed);
       fclose(stream1);
       fclose(stream2);
       return 0;

       /********************************************************************
          The output should be:

          Number of files flushed = 5
       ********************************************************************/
    }

close -- Close File Associated with Handle
fclose -- Close Stream
fflush -- Write Buffer to File
<stdio.h>