The fopen_s () function, can I somehow do without the second argument of the filename if I don’t need it in this function to open a nameless text file?
- 2What do you mean not needed? And what are you going to open? This parameter is required - zenden2k
- maybe a person wants to open a nameless file. In order for everything to work, there was no file (and this is almost possible - you just need to delete the file after opening it). - KoVadim
- And what do you think is a "nameless file"? The question is serious. - VladD
- nameless file - file with no name. And this may be necessary. Options for implementation - opens a file in the temp directory, and then immediately deleted. As a result, there is a descriptor, you can read-write into it, and when the application is closed, it is deleted. In the file system, it is visible for a split second. The second way is to make a simulation and create a file in RAM. - KoVadim
1 answer
In C, there are no overloaded functions or default arguments.
According to standard C (6.5.2.2 Function calls)
If you’re talking about the number of parameters .
and
If you don’t need to be a type, it doesn’t include a prototype.
As for the file name, then (stv C, 7.21.3 Files)
8 Functions that open additional (nontemporary) files require a file name , which is a string. The rules for composing valid file names are the implementation-defined . It can be implemented.
For example, I tried to create a file with an "empty name" using an online compiler, that is, in the form "" , then it was not created.
Here is a demo program.
#include <stdio.h> int main( void ) { FILE *output; output = fopen( "", "w" ); if ( output ) puts( "File was created" ); else puts( "File was not created" ); if ( output ) fclose( output ); } Output to console:
File was not created In this program, the function call fopen can be replaced with the function call fopen_s .