tmpfile

Description

Creates a temporary file.

#include <stdio.h>

FILE *tmpfile( void );

Remarks

The tmpfile function creates a temporary file and returns a pointer to that stream. If the file cannot be opened, tmpfile returns a NULL pointer.

This temporary file is automatically deleted when the file is closed, when the program terminates normally, or when _rmtmp is called, assuming that the current working directory does not change. The temporary file is opened in w+b (binary read/write) mode.

Return Value

If successful, the tmpfile function returns a stream pointer. Otherwise, it returns a NULL pointer.

Compatibility

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

_rmtmp, _tempnam, tmpnam

Example

/* TMPFILE.C: This program uses tmpfile to create a temporary file,

* then deletes this file with _rmtmp.

*/

#include <stdio.h>

void main( void )

{

FILE *stream;

char tempstring[] = “String to be written”;

int i;

/* Create temporary files. */

for( i = 1; i <= 10; i++ )

{

if( (stream = tmpfile()) == NULL )

perror( “Could not open new temporary file\n” );

else

printf( “Temporary file %d was created\n”, i );

}

/* Remove temporary files. */

printf( “%d temporary files deleted\n”, _rmtmp() );

}

Output

Temporary file 1 was created

Temporary file 2 was created

Temporary file 3 was created

Temporary file 4 was created

Temporary file 5 was created

Temporary file 6 was created

Temporary file 7 was created

Temporary file 8 was created

Temporary file 9 was created

Temporary file 10 was created

10 temporary files deleted