This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
prog-103-p-05-2030/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c
T
2026-02-19 16:22:54 +01:00

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;
}