tmpnam
char *  tmpnam ( char * buffer );
stdio.h
  cplusplus.com  

Generate a unique temporary filename.
  A string containing a unique filename is generated.
  This string can be used to create a temporary file without overwriting any existing one.
  If the buffer parameter is NULL, the resulting string is stored in an internal static array that can be accessed by the return value. The content of this string is stored until a further call to this function erases it.
  If the buffer parameter is not NULL, it must point to an array of at least L_tmpnam bytes that will be filled with the proposed tempname. L_tmpnam is a contant defined in stdio.h

Parameters.

buffer
Pointer to an array of L_tmpnam (defined in stdio.h) bytes, where the proposed tempname will be stored.
You can also specify a NULL pointer. In this case the string will be stored in an internal static array.

Return Value.
  A pointer to the string containing the proposed name for a temporary file. If NULL was specified as the buffer this points to an internal buffer that will be overwritten the next time this function is called, otherwise it returns the buffer parameter.
  If an error occurs this function returns NULL.

Portability.
  Defined in ANSI-C.

Example.

/* tmpnam example */
#include <stdio.h>

main ()
{
  char buffer [L_tmpnam];
  char * pointer;

  tmpnam (buffer);
  printf ("Tempname #1: %s\n",buffer);

  pointer = tmpnam (NULL);
  printf ("Tempname #2: %s\n",pointer);

  return 0;  
}

This program will generate two different names for temporary files. Each one has been created by one of the two methods how tmpnam can be used.

See also.
  fopen, tmpfile


© The C++ Resources Network, 2000