C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
TEMPNAME.C
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* TEMPNAME.C illustrates:
 *      tmpnam          _tempnam
 */
 
#include <stdio.h>
 
void main()
{
    char *name1, name2[L_tmpnam], *name3;
    int c;
 
    /* Create several temporary file names using internal buffer. */
    for( c = 0; c < 5; c++ )
        if( (name1 = tmpnam( NULL )) != NULL )
            printf( "%s is a safe temporary file name.\n", name1 );
 
    /* Create a temporary file name using external buffer. */
    if( tmpnam( name2 ) != NULL )
        printf( "%s is a safe temporary file name.\n", name2 );
 
    /* Create a temporary file name with prefix TEMP and place it in
     * the first of these directories that exists:
     *   1. TMP environment directory
     *   2. C:\TEMPFILE
     *   3. P_tmpdir directory (defined in stdio.h)
     */
    if( (name3 = _tempnam( "C:\\TEMPFILE", "TEMP" )) != NULL )
        printf( "%s is a safe temporary file name.\n", name3 );
}
                                    -♦-