write_all_in_one
This commit is contained in:
@@ -16,6 +16,15 @@ int write_one_by_one(char *filename, const char *text){
|
|||||||
return 0;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
// does_exist.txt contains: "something which will be replaced"
|
// 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
|
// The opening should succeed as it creates the file if needed
|
||||||
// However it can fail if the file's access is forbidden
|
// 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
Now I exist
|
||||||
Binary file not shown.
Reference in New Issue
Block a user