summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2025-02-22 22:43:59 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2025-02-22 22:43:59 +0100
commitd7e5815872cd043f905114bffff608c7792cd417 (patch)
tree6a9868d74321e32a94903229784753a45163c2cb /main.c
parentafabc09085d80aeee4a4a4131ed8cfca6120f321 (diff)
working on the making a copy of a file, so reading the contents and making a new file and writing to it the contents of the previous file
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.c b/main.c
index 21c65a1..b6d8828 100644
--- a/main.c
+++ b/main.c
@@ -158,6 +158,25 @@ void change_ownership(const char *path) {
void copy_files(const char *arg) {
// split the argument into the source and destination
// make a copy of the source file in the destination file
+ int c;
+
+ FILE *pold_file = fopen(argument.source, "r");
+ if (pold_file == NULL) {
+ perror("cant open the source file for reading (copy failed) ");
+ return;
+ }
+
+ FILE *pnew_file = fopen(argument.destination, "w");
+ if (pnew_file == NULL) {
+ perror("cant open the destination file for reading (copy failed)");
+ return;
+ }
+
+ while ((c = fgetc(pold_file)) != EOF) {
+ fputc(c, pnew_file);
+ }
+ fclose(pnew_file);
+ fclose(pold_file);
}
void move_files(const char *arg) {