Format
#include <stdio.h> char *tempnam(char *dir, char *prefix);
Language Level: XPG4, Extension
tempnam creates a temporary file name in another directory. The prefix
is the prefix to the file name. tempnam tests for the existence
of the file with the given name in the following directories,
listed in order of precedence:
Notes:
Return Value
tempnam returns a pointer to the temporary name, if
successful. If the name cannot be created or it already exists,
tempnam returns the value NULL.
Example
This example creates a temporary file name using the
directory d:\tmp:
#include <stdio.h> #include <stdlib.h>
int main(void)
{
char *name1;
if ((name1 = tempnam("d:\\tmp", "stq")) != NULL)
printf("%s is safe to use as a temporary file.\n", name1);
else {
printf("Cannot create unique filename\n");
return EXIT_FAILURE;
}
return 0;
/**************************************************************
The output should be similar to:
D:\tmp\stqU3CP2.C2T is safe to use as a temporary file. **************************************************************/ }
![]()
malloc -- Reserve Storage Block
_rmtmp -- Remove Temporary Files
tmpfile -- Create Temporary File
tmpnam -- Produce Temporary File Name
<stdio.h>