Easy Tutorial
❮ C Recursion C Function Wctomb ❯

C Library Function - tmpnam()

C Standard Library - <stdio.h>

Description

The C library function char *tmpnam(char *str) generates and returns a valid temporary filename that does not exist before. If str is NULL, it only returns the temporary filename.

Declaration

Here is the declaration for the tmpnam() function.

char *tmpnam(char *str)

Parameters

Return Value

Example

The following example demonstrates the use of the tmpnam() function.

#include <stdio.h>

int main()
{
   char buffer[L_tmpnam];
   char *ptr;

   tmpnam(buffer);
   printf("Temporary name 1: %s\n", buffer);

   ptr = tmpnam(NULL);
   printf("Temporary name 2: %s\n", ptr);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

Temporary name 1: /tmp/filebaalTb
Temporary name 2: /tmp/filedCIbb0

C Standard Library - <stdio.h>

❮ C Recursion C Function Wctomb ❯