Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <stdio.h>
FILE *tmpfile(void);
Creates a temporary binary file. It opens the temporary file in wb+ mode. The file is automatically removed when it is closed or when the program is terminated.
If successful, tmpfile() returns a pointer to the stream associated with the file created.
If tmpfile() cannot open the file, it returns a NULL pointer. On normal termination (exit()), these temporary files are removed. On abnormal termination, an effort is made to remove these files.
When the calling application is a z/OS® UNIX program, the temporary file is created in the hierarchical file system. The file is created in the directory referred to by the TMPDIR environment variable, or '/tmp' if TMPDIR is not defined.
⁄* CELEBT13
This example creates a temporary file and if successful,
writes tmpstring to it.
At program termination, the file is removed.
*⁄
#include <stdio.h>
int main(void) {
FILE *stream;
char tmpstring[ ] = "This string will be written";
{
if((stream = tmpfile( )) == NULL)
printf("Cannot make a temporary file\n");
else
fprintf(stream, "%s", tmpstring);
}
}