Standard Library Functions in C

adplus-dvertising
tmpnam() Function
Previous Home Next

Description

The C library function, The tmpnam( ) function generates a temporary filename that can be used to open a temporary file without overwriting an existing file. This name is stored in string. If string is NULL, then tmpnam leaves the result in an internal static buffer. Thus any subsequent calls destroy this value. If string is not NULL, it is assumed to point to an array of at least L_tmpnam characters — or L_tmpnam bytes. The value of L_tmpnam is defined in STDIO.H. The function generates unique filenames for up to TMP_MAX calls.

Declaration

Following is the declaration for tmpnam() function.

char *tmpnam( char *string )

Parameters

String - The character array to copy the file name.

Return Value

Upon successful completion, tmpnam() shall return a pointer to a string. If no suitable string can be generated, the tmpnam() function shall return a null pointer. If the argument s is a null pointer, tmpnam() shall leave its result in an internal static object and return a pointer to that object. Subsequent calls to tmpnam() may modify the same object. If the argument s is not a null pointer, it is presumed to point to an array of at least L_tmpnam chars; tmpnam() shall write its result in that array and shall return the argument as its value.

Example

#include <stdio.h>
 
int main(void)
{
    char name[40];
    int i;

    for(i=0; i<3; i++) 
	{
      tmpnam(name);
      printf("%s ", name);
    }
    return 0;
 }
Previous Home Next