tmpfile()

Opens a temporary file.

  #include <stdio.h>
  
  FILE *tmpfile(void);    
Remarks

The tmpfile() function creates and opens a binary file for output that is automatically removed when it is closed or when the program terminates.

The tmpfile() function returns a pointer to the FILE variable of the temporary file if it is successful. If it fails, tmpfile() returns a null pointer ( NULL).

This facility may not be available on configurations of the EWL that run on platforms without file systems.

The rename() function changes the name of a file, specified by old to the name specified by new. rename() returns a nonzero if it fails and returns zero if successful.

Listing: Example of tmpfile() usage

#include <stdio.h>

#include <stdlib.h>

int main(void)

{

FILE *f;

// Create a new temporary file for output

if ( (f = tmpfile()) == NULL) {

printf("Can't open temporary file.\n");

exit(1);

}

// Output text to the temporary file

fprintf(f, "watch clock timer glue\n");

// Close and delete the temporary file.

fclose(f);

return 0;

}