From 84785a1cf4a8505a6c65d19afcd9656b19822711 Mon Sep 17 00:00:00 2001 From: Abdellah El Morabit Date: Mon, 24 Feb 2025 08:48:26 +0100 Subject: i was getting errors becasue i was passing structures into the execute structure while it was expecting a const char; but i ended up splitting up the char using the split_command and passing thazt result into the variable which apparently fixes the problem --- main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index dcad1f2..f1feecf 100644 --- a/main.c +++ b/main.c @@ -42,9 +42,11 @@ void remove_file(const char *path); void remove_dir(const char *path); // trying to delete the folder and the files init recursively -void copy_files(struct split_arg argument); +// void copy_files(struct split_arg argument); +void copy_files(const char *arg); -void move_files(struct split_arg argument); +// void move_files(struct split_arg argument); +void move_files(const char* arg); void print_cdirectory(const char *arg); @@ -148,7 +150,8 @@ void remove_dir(const char *path) { perror("failed to delete the directory"); } else { struct dirent *entry; - const DIR *dP = opendir(path); + // cant be a const because inserting it into the readdir functions causes a warning becasue it expects a non const dir variable + DIR *dP = opendir(path); if (dP == NULL) { perror("failed to open the directory to delete the files recursively"); @@ -185,10 +188,11 @@ void change_ownership(const char *path) { } } -void copy_files(const struct split_arg argument) { +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; + struct split_arg argument = split_argument((struct command){.arg = (char *)arg}); FILE *pold_file = fopen(argument.source, "r"); if (pold_file == NULL) { @@ -209,7 +213,10 @@ void copy_files(const struct split_arg argument) { fclose(pold_file); } -void move_files(const struct split_arg argument) { +void move_files(const char *arg) { + + struct split_arg argument = split_argument((struct command){.arg = (char *)arg}); + if (remove(argument.source) != 0) { perror("failed while trying to move the file"); } -- cgit v1.2.3-70-g09d2