C Library Function - tmpfile()
Description
C library function *FILE tmpfile(void) Creates a temporary file in binary update mode (wb+). The created temporary file is automatically deleted when the stream is closed or when the program terminates.
Declaration
Below is the declaration of the tmpfile() function.
FILE *tmpfile(void)
Parameters
- NA
Return Value
If successful, the function returns a stream pointer to the created temporary file. If the file was not created, it returns NULL.
Example
The following example demonstrates the use of the tmpfile() function.
#include
int main ()
{
FILE *fp;
fp = tmpfile();
printf("临时文件被创建\n");
/* You can use temporary files here */
fclose(fp);
return(0);
}
Let's compile and run the above program; it will create a temporary file in the /tmp folder, but once the program exits, the temporary file is automatically deleted, and the program produces the following result:
临时文件被创建
C Standard Library -