rachelason
Programmer
HI!
I want to create unique file names using _mktemp with extension.
This is a code i picked up from MSDN. But if i add .doc or any other extension in the temp pointer, it throws an error. I tried using another variable and concatenating with the original name,,, no good.
any suggestion? Thanks
#include <io.h>
#include <string.h>
#include <stdio.h>
char *temp = "fnXXXXXX";
char *result;
char names[5][20];
int main( void )
{
int i;
FILE *fp;
for( i = 0; i < 5; i++ )
{
strcpy( names, temp );
/* Attempt to find a unique filename: */
result = _mktemp( names);
if( result == NULL )
printf( "Problem creating the template" );
else
{
if( (fp = fopen( result, "w" )) != NULL )
printf( "Unique filename is %s\n", result );
else
printf( "Cannot open %s\n", result );
fclose( fp );}
} return 0;
}
I want to create unique file names using _mktemp with extension.
This is a code i picked up from MSDN. But if i add .doc or any other extension in the temp pointer, it throws an error. I tried using another variable and concatenating with the original name,,, no good.
any suggestion? Thanks
#include <io.h>
#include <string.h>
#include <stdio.h>
char *temp = "fnXXXXXX";
char *result;
char names[5][20];
int main( void )
{
int i;
FILE *fp;
for( i = 0; i < 5; i++ )
{
strcpy( names, temp );
/* Attempt to find a unique filename: */
result = _mktemp( names);
if( result == NULL )
printf( "Problem creating the template" );
else
{
if( (fp = fopen( result, "w" )) != NULL )
printf( "Unique filename is %s\n", result );
else
printf( "Cannot open %s\n", result );
fclose( fp );}
} return 0;
}