This is how I open the file for writing +:
if( fopen_s( &f, fileName, "w+" ) !=0 ) { printf("Open file failed\n"); return; } fprintf_s(f, "content");
If the file does not exist, the open operation fails. What is the right way for fopenif I want to create a file automatically if the file does not already exist?
fopen
EDIT: If the file exists, I would like fprintf to overwrite the file rather than adding it.
To overwrite any existing file, use the call creat:
creat
#include <fcntl.h> #include <stdio.h> int fd = creat (fileName, 0666); // creates file if not exist, overwrite existing FILE *f = fdopen (fd, "w"); // optional, if FILE * type desired
fopen(name, "w")? , , , , , , perror().
fopen(name, "w")
perror()
, ( , ) MSVC _s, . , , , :
_s
, (, strcat())
strcat()
/ (, strerror()),
strerror()
. , ( fopon_s()) - , . ( C - MS , .)
fopon_s()
Source: https://habr.com/ru/post/1782318/More articles:WPF library or room decoration tool - designSyntax / Boolean Validation In Javascript? - javascriptWPF 2d text library - vector-graphicsPrinting an HTML page in landscape mode? - htmlWhat is the difference between Response.Close () and Response.Dispose ()? - c #What do you call C functions from MacRuby? - macrubytwo queries give different results in one database - mysqlWhere is the .rspec configuration file located? - ruby-on-railsLinks are not expanded when using ResolveReferences and _CopyWebApplication in AfterBuild - asp.netimport existing source code as a reference library in eclipse - build-processAll Articles