Format
#include <stdio.h> char *tmpnam(char *string);
Language Level: ANSI, POSIX, XPG4
tmpnam produces a valid file name that is not the same as the
name of any existing file. It stores this name in string.
If string is NULL, tmpnam leaves the result in an
internal static buffer. Any subsequent calls destroy this value.
If string is not NULL, it must point to an array of at
least L_tmpnam bytes. The value of L_tmpnam is defined in
<stdio.h>.
On both OS/2 and Windows, tmpnam produces a different name each time it is called within a module up to at least TMP_MAX (a value of at least 25) names. Note that files created using names returned by tmpnam are not automatically discarded at the end of the program.
Return Value
tmpnam returns a pointer to the name. If it cannot
create a unique name; it returns NULL.
Example
This example calls tmpnam to produce a valid file name.
#include <stdio.h>
int main(void)
{
char *name1;
if ((name1 = tmpnam(NULL)) !=NULL)
printf("%s can be used as a file name.\n", name1);
else
printf("Cannot create a unique file name\n");
return 0;
/*******************************************************
The output for OS/2 should be similar to:
d:\tmp\acc00000.CTN can be used as a file name *******************************************************/ }
![]()
fopen -- Open Files
remove -- Delete File
tempnam -- Produce Temporary File Name
<stdio.h>