diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-02-22 22:43:59 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-02-22 22:43:59 +0100 |
| commit | d7e5815872cd043f905114bffff608c7792cd417 (patch) | |
| tree | 6a9868d74321e32a94903229784753a45163c2cb | |
| parent | afabc09085d80aeee4a4a4131ed8cfca6120f321 (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
| -rw-r--r-- | main.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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) { |
