Function tmpfile () in C

Function FILE * tmpfile (void) in standard C Library Create temporary files in wb + mode. The temporary file created will be automatically deleted when the stream is closed (fclose function) or when the program ends.

Function FILE * tmpfile (void) in standard C Library Create temporary files in wb + mode. The temporary file created will be automatically deleted when the stream is closed (fclose function) or when the program ends.

Declare the function tmpfile () in C

Below is the declaration for the function tmpfile () in C:

 FILE * tmpfile ( void ) 

Parameters

This function does not receive any parameters.

Returns the value

If successful, this function returns a pointer to the temporary file created. If this file cannot be created, then the function returns NULL.

For example

The following program C illustrates the usage of the function tmpfile () in C:

 #include int main () { FILE * fp ; fp = tmpfile (); printf ( "Mot file tam thoi duoc tao !!!n" ); /* truoc khi su dung fclose, ban co the su dung file tam thoi nay */ fclose ( fp ); return ( 0 ); } 

Compile and run the above program to create a temporary file in / tmp folder but when the program exits, it will automatically be deleted and the program will produce the following result:

Function tmpfile () in C Picture 1Function tmpfile () in C Picture 1

According to Tutorialspoint

Previous lesson: Function setvbuf () in C

Next lesson: Function tmpnam () in C

4 ★ | 2 Vote