32 lines
718 B
C
32 lines
718 B
C
|
|
|
|
|
|
#include <stdio.h>
|
|
int write_one_by_one(char *filename, const char *text){
|
|
|
|
FILE *file = fopen(filename, "rw");
|
|
if(!file) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
// does_exist.txt contains: "something which will be replaced"
|
|
int a = write_one_by_one("does_exist.txt", "Hello World!");
|
|
// does_exist.txt contains: "Hello World!"
|
|
|
|
// does_not_exist.txt... does not exist.
|
|
int b = write_one_by_one("does_not_exist.txt", "Now I exist");
|
|
// does_not_exist.txt... now exists and contains: "Now I exist"
|
|
|
|
printf("%d %d\n", a, b); // 0 0
|
|
// The opening should succeed as it creates the file if needed
|
|
// However it can fail if the file's access is forbidden
|
|
|
|
return 0;
|
|
}
|
|
|