tmpnam Function

Creates a unique temporary filename.

Attention: This function is not implemented by MPLAB XC8.

Include

<stdio.h>

Prototype

char *tmpnam(char * s);

Argument

s
pointer to the temporary name

Return Value

Returns a pointer to the filename generated and stores the filename in s. If it can not generate a filename, the NULL pointer is returned.

Remarks

The created filename will not conflict with an existing file name. Use L_tmpnam to define the size of array the argument of tmpnam points to.

Example

#include <stdio.h>

int main(void)
{
  char *myfilename;
  char mybuf[L_tmpnam];
  char *myptr = (char *) &mybuf;

  if ((myfilename = tmpnam(myptr)) == NULL)
    printf("Cannot create temporary file name");
  else
    printf("Temporary file %s was created", myfilename);
}

Example Output

Temporary file ctm00001.tmp was created