write_all_in_one

This commit is contained in:
2026-02-19 17:51:15 +01:00
parent e89bfaa46d
commit 689311b84e
4 changed files with 24 additions and 1 deletions
@@ -16,6 +16,15 @@ int write_one_by_one(char *filename, const char *text){
return 0;
}
int write_all_in_one(char *filename, const char *text){
FILE *file = fopen(filename, "w");
if(!file)return 1;
fprintf(file, text);
return 0;
}
/*
int main()
{
// does_exist.txt contains: "something which will be replaced"
@@ -30,6 +39,19 @@ int main()
// The opening should succeed as it creates the file if needed
// However it can fail if the file's access is forbidden
// does_exist.txt contains: "Hello World!"
a = write_all_in_one("does_exist.txt", "What a good day!");
// does_exist.txt contains: "What a good day!"
// still_not_yet_exist.txt... does not exist.
b = write_all_in_one("still_not_yet_exist.txt", "Now I exist");
// still_not_yet_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;
}
*/
@@ -0,0 +1 @@
Now I exist
Binary file not shown.