tmpfile

create a temporary binary file

Synopsis:

#include <stdio.h>
FILE *tmpfile( void );

Description:

The tmpfile() function creates a temporary binary file that's automatically removed when it's closed or when the program terminates. The file is opened in update mode.

When a stream is opened in update mode, both reading and writing may be performed. However, writing may not be followed by reading without an intervening call to the fflush() function, or to a file-positioning function (fseek(), fsetpos(), rewind()). Similarly, reading may not be followed by writing without an intervening call to a file-positioning function, unless the read resulted in end-of-file.

Returns:

The tmpfile() function returns a pointer to the stream of the file that it created. If the file cannot be created, the tmpfile() function returns NULL. When an error has occurred, errno contains a value that indicates the type of error that has been detected.

See also:

errno, fopen(), freopen(), tmpnam()

Examples:

#include <stdio.h>

static FILE *TempFile;

void main()
  {
    TempFile = tmpfile();
    /* . */
    /* . */
    /* . */
    fclose( TempFile );
  }

Classification:

ANSI

Systems:

All (except DOS/PM)