I am not sure what you want to do, but my guess is that you want to save a string into a FILE pointer, without actually saving that file to the hard drive.
You can specify the “T†and/or “D†flags when you call fopen() in the mode.
So, if your string is szBuffer[MAX_PATH] and you want to save the path of your executable file into a file, but without saving it to hard drive,
char szBuffer[MAX_PATH];
GetModuleFileName( NULL, szBuffer, MAX_PATH );
FILE * pFile = fopen( "C:\\Temp.txt", "wtT" );
fprintf( pFile, "The path to my executable is %s.\n", szBuffer );
fclose( pFile );
Here we filled a string with whatever value we wanted, and then made a temporary file in which to store it.
The file was opened in wtT mode, which means it was created for writing, overwritten if existing, formatted for text, and temporary—not flushed to disk if possible.
The reason you would want to use this is if you are extracting a small file out of a large archive.
You could store the small file into a FILE stream but without actually writing it to disk.
Then you can read from the file as if it was a normal FILE, close it, and be done with it.
Specifying D in the mode means the file is temporary, and will be written to disk, but will be deleted after you close it.
L. Spiro