tmpfile -- Create Temporary File

Format

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

Language Level: ANSI, POSIX, XPG4
tmpfile creates a temporary binary file. The file is automatically removed when it is closed or when the program is terminated.

tmpfile opens the temporary file in wb+ mode.

Return Value
tmpfile returns a stream pointer, if successful. If it cannot open the file, it returns a NULL pointer. On normal termination (exit), these temporary files are removed.

Example
This example creates a temporary file, and if successful, writes tmpstring to it. At program termination, the file is removed.

#include <stdlib.h>
#include <stdio.h>
FILE *stream;
char tmpstring[ ] = "This is the string to be temporarily written";
int main(void)
{
   if((stream = tmpfile( )) == NULL) {
      perror("Cannot make a temporary file");
      return EXIT_FAILURE;
   }
   else
      fprintf(stream, "%s", tmpstring);
   return 0;
}


fopen -- Open Files
tmpnam -- Produce Temporary File Name
tempnam -- Produce Temporary File Name
_rmtmp -- Remove Temporary Files
<stdio.h>