push pour cours

This commit is contained in:
2026-02-19 16:22:54 +01:00
parent 9823026e15
commit 4267dbf694
2 changed files with 130 additions and 0 deletions
@@ -0,0 +1,31 @@
#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;
}