diff --git a/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c b/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c index ca9f137..3894c6a 100644 --- a/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c +++ b/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c @@ -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; } - +*/ diff --git a/Who_robbed_Thibouvre/fundamentals/basic_write/does_exist.txt b/Who_robbed_Thibouvre/fundamentals/basic_write/does_exist.txt index 3615520..77cf452 100644 Binary files a/Who_robbed_Thibouvre/fundamentals/basic_write/does_exist.txt and b/Who_robbed_Thibouvre/fundamentals/basic_write/does_exist.txt differ diff --git a/Who_robbed_Thibouvre/fundamentals/basic_write/still_not_yet_exist.txt b/Who_robbed_Thibouvre/fundamentals/basic_write/still_not_yet_exist.txt new file mode 100644 index 0000000..7b5bbbf --- /dev/null +++ b/Who_robbed_Thibouvre/fundamentals/basic_write/still_not_yet_exist.txt @@ -0,0 +1 @@ +Now I exist \ No newline at end of file diff --git a/Who_robbed_Thibouvre/fundamentals/basic_write/test b/Who_robbed_Thibouvre/fundamentals/basic_write/test index 9857cff..aada1d1 100755 Binary files a/Who_robbed_Thibouvre/fundamentals/basic_write/test and b/Who_robbed_Thibouvre/fundamentals/basic_write/test differ