6.18.46 tmpfile Function

Creates a temporary file.

Attention: This function is not implemented by MPLAB XC8.

Include

<stdio.h>

Prototype

FILE * tmpfile(void)

Return Value

Returns a stream pointer if successful; otherwise, returns a NULL pointer.

Remarks

tmpfile creates a file with a unique filename. The temporary file is opened in w+b (binary read/write) mode. It will automatically be removed when exit is called; otherwise the file will remain in the directory. This function requires a heap.

Example

#include <stdio.h>
int main(void)
{
  FILE *mytempfile;

  if ((mytempfile = tmpfile()) == NULL)
    printf("Cannot create temporary file");
  else
    printf("Temporary file was created");
}

Example Output

Temporary file was created