Syntax
#include <stdio.h> FILE *tmpfile(void);Description
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.
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.
This example creates a temporary file, and if successful, writes tmpstring to it. At program termination, the file is removed.
#include <stdio.h>
#include <stdlib.h>
FILE *stream;
char tmpstring[] = "This is the string to be temporarily written";
int main(void)
{
if (NULL == (stream = tmpfile())) {
perror("Cannot make a temporary file");
return EXIT_FAILURE;
}
else
fprintf(stream, "%s", tmpstring);
return 0;
}
Related Information