Use tmpfile function to read/write temporary file
Syntax
C tmpfile function has the following syntax.
FILE *tmpfile(void);
Header
C tmpfile function is from header file stdio.h.
Description
C tmpfile function opens a temporary binary file for read/write operations and returns a pointer to the stream.
C tmpfile function returns a null pointer on failure.
The temporary file created by tmpfile()
is automatically removed when the file is closed or
when the program terminates.
You can open TMP_MAX
temporary files (up to the limit set by FOPEN_MAX
).
Example
C tmpfile function creates a temporary file
#include <stdio.h>
/* ww w . j a va2 s. com*/
int main(void){
FILE *temp;
if((temp=tmpfile())==NULL) {
printf("Cannot open temporary work file.\n");
exit(1);
}
}