_tempnam() always returns a filename in the "c:\\temp" directory, regardless of the parameters. This example was extracted from MSDN. I need to generate a unique filename in a directory other than c:\temp -- any ideas how to do that other than writing my own function? maybe a c++ solution?
Note this is one of may examples where Microsoft uses void main() instead of int main() :evil: Not that I mind -- but can be confusing to newbes.
Thanks
#include <stdio.h>
void main( void )
{
char *name2;
/* Create a temporary filename in temporary directory with the
* prefix "stq". The actual destination directory may vary
* depending on the state of the TMP environment variable and
* the global variable P_tmpdir.
*/
if( ( name2 = _tempnam( "c:\\h", "stq" ) ) != NULL )
{
printf( "%s is safe to use as a temporary file.\n", name2 );
FILE*fp = fopen(name2,"wt");
fprintf(fp,"Hello World\n");
fclose(fp);
}
else
printf( "Cannot create a unique filename\n" );
}