Use C tmpnam function to create unique file name
Syntax
C tmpnam function has the following syntax.
char *tmpnam(char *name);
Header
C tmpnam function is
from header file stdio.h
.
Description
C tmpnam function generates a unique filename.
*name
should be at least L_tmpnam
characters long.
L_tmpnam
is defined in stdio.h.
C tmpnam function return the unique temp name on success or a null pointer on error.
The function can be called up to TMP_MAX times. TMP_MAX is defined in stdio.h, and it will be at least 25.
Example
Use C tmpnam function to create unique file name. And display three unique temporary filenames
#include <stdio.h>
/* ww w . java2s . co m*/
int main(void)
{
char name[40];
int i;
for(i=0; i<3; i++) {
tmpnam(name);
printf("%s ", name);
}
return 0;
}