home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / file / tempname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-06  |  744 b   |  27 lines

  1. /* TEMPNAME.C illustrates:
  2.  *      tmpnam          tempnam
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. main()
  8. {
  9.     char *name1, *name2;
  10.     int c;
  11.  
  12.     /* Create several temporary file names in the current directory. */
  13.     for( c = 0; c < 5; c++ )
  14.         if( (name1 = tmpnam( NULL )) != NULL )
  15.             printf( "%s is a safe temporary file name.\n", name1 );
  16.  
  17.     /* Create a temporary file name with prefix TEMP and place it in
  18.      * the first of these directories that exists:
  19.      *   1. TMP environment directory
  20.      *   2. C:\TEMPFILE
  21.      *   3. P_tmpdir directory (defined in stdio.h)
  22.      */
  23.     if( (name2 = tempnam( "C:\\TEMPFILE", "TEMP" )) != NULL )
  24.         printf( "%s is a safe temporary file name.\n", name2 );
  25.  
  26. }
  27.