This code works for me :
void TestOtherCode()
{
FilePath fileName = { 0 };
GetEnvironmentVariable( "USERPROFILE", fileName, MAX_PATH );
if( ! fileName[ 0 ] )
{
printf( "unable to obtain environment variable\n" );
return;
}
PathAddBackslash( fileName ); strcat( fileName, "Desktop\\TestFile.txt" );
FILE * fp = fopen( fileName, "w" );
if( ! fp )
{
printf( "failed to open %s\n", fileName );
return;
}
fprintf( fp, "a line of text\n" );
printf( "test concluded\n" );
}
This tells me that it can be done but you are doing something incorrectly. I would start by verifying the name of the file you are writing too. This code demonstrates one way you can obtain it.