Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - tmpnam()

C Library Function - tmpnam()

C Standard Library - <stdio.h> C Standard Library -

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

Return Value

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 - <stdio.h> C Standard Library -