commit f317faae73727d54986994604c4eef675437650f
parent 61245b51cd78150f9f2522b1a169e42d646254d4
Author: qorg11 <qorg@vxempire.xyz>
Date: Wed, 17 Jun 2020 21:53:57 +0200
Aded cp and mv
Diffstat:
A | src/cp.c | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
A | src/mv.c | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/src/cp.c b/src/cp.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+
+int
+copy(const char *src, const char *dst)
+{
+ FILE *source = fopen(src,"r");
+ FILE *destination = fopen(dst,"w");
+ if(destination == NULL)
+ {
+ printf("Error opening destination file\n");
+ return 1;
+ }
+ if(source == NULL)
+ {
+ printf("Error opening source file\n");
+ return 1;
+ }
+
+ char c;
+
+ while((c = fgetc(source)) > 0)
+ {
+ int value = fputc(c,destination);
+ if(value == -1)
+ {
+ printf("Error\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int
+main(int argc, char *argv[])
+{
+ if (argc == 1)
+ {
+ fprintf(stderr,"usage: cp source destination\n");
+ return 1;
+ }
+ else
+ copy(argv[1],argv[2]);
+
+}
diff --git a/src/mv.c b/src/mv.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+
+int
+move(const char *src, const char *dst)
+{
+ FILE *source = fopen(src,"r");
+ FILE *destination = fopen(dst,"w");
+ if(destination == NULL)
+ {
+ printf("Error opening destination file\n");
+ return 1;
+ }
+ if(source == NULL)
+ {
+ printf("Error opening source file\n");
+ return 1;
+ }
+
+ char c;
+
+ while((c = fgetc(source)) > 0)
+ {
+ int value = fputc(c,destination);
+ if(value == -1)
+ {
+ printf("Error\n");
+ return 1;
+ }
+ }
+ remove(src);
+ return 0;
+}
+
+int
+main(int argc, char *argv[])
+{
+ if (argc == 1)
+ {
+ fprintf(stderr,"usage: cp source destination\n");
+ return 1;
+ }
+ else
+ move(argv[1],argv[2]);
+
+}