C Library Function - tmpnam()
Description
C library function **char tmpnam(char str) generates and returns a valid temporary filename that did not previously exist. If str is null, only the temporary filename is returned.
Declaration
Below is the declaration of the tmpnam() function.
char *tmpnam(char *str)
Parameters
- str -- This is a pointer to a character array in which the temporary filename will be stored as a C string.
Return Value
- A pointer to a C string that stores the temporary filename. If str is a null pointer, the pointer points to an internal buffer that is overwritten the next time the function is called.
- If str is not a null pointer, str is returned. If the function fails to successfully create a usable filename, a null pointer is returned.
Example
The following example demonstrates the use of the tmpnam() function.
#include
int main()
{
char buffer[L_tmpnam];
char *ptr;
tmpnam(buffer);
printf("临时名称 1: %s\n", buffer);
ptr = tmpnam(NULL);
printf("临时名称 2: %s\n", ptr);
return(0);
}
Let's compile and run the above program, which will produce the following result:
临时名称 1: /tmp/filebaalTb
临时名称 2: /tmp/filedCIbb0
C Standard Library -