C library functions - tmpnam ()
C standard library - <stdio.h>
description
C library functionschar * tmpnam (char * str) generates and returns a valid temporary filename, before the file name does not exist.Ifstr is null, then only return to the temporary file name.
statement
Here is () statement tmpnam function.
char *tmpnam(char *str)
parameter
- str - This is a pointer to an array of characters, in which the temporary file name is stored as a C string.
return value
- Pointing to a C string pointer, the string stored in the temporary file name. If str is a null pointer, the pointer to an internal buffer, the buffer is overwritten the next time the function is called.
- If str is not a null pointer, then return str. If the function fails to successfully create the file name is available, it returns a null pointer.
Examples
The following example demonstrates the tmpnam () function is used.
#include <stdio.h> 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 result in the following:
临时名称 1: /tmp/filebaalTb 临时名称 2: /tmp/filedCIbb0