This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
prog-103-p-05-2030/Who_robbed_Thibouvre/fundamentals/my_cp/my_cp.c
T
2026-02-23 01:15:30 +01:00

48 lines
1.1 KiB
C

#include <stdio.h>
int my_cp(const char *src, const char *dest){
FILE *file_src = fopen(src, "r");
if(!file_src) return 1;
FILE *file_dest = fopen(dest, "w");
/*if (!file_dest) {
fclose(file_src);
return 1;
}*/
//On ecrase les data de dest par celles de src
//pas opti à voir si la mouli accepte
int c = fgetc(file_src);
while(c != EOF){
fputc(c, file_dest);
c = fgetc(file_src);
}
fclose(file_src);
fclose(file_dest);
return 0;
}
/*
int main()
{
//example.txt <-- Create a copy of me!
//trashy.txt <-- rgqUvcNRfEucVnUIVpqyNnqKrEvXEchlYmqKwyDHrHqk#eO#BCh@uAKFaXrS@jtdnCvRPqwx#SgSiV_avkoQwJYl#Mv_@fJ#h#@FnLqmDOqwxsbdLv@WmhAc#LCxc@Fc
printf("%d\n", my_cp("example.txt", "trashy.txt")); // 0
printf("%d\n", my_cp("new_file.txt", "example.txt")); // 1
printf("%d\n", my_cp("example.txt", "new_file.txt")); // 0
//example.txt <-- Create a copy of me!
//trashy.txt <-- Create a copy of me!
//new_file.txt <-- Create a copy of me!
return 0;
}*/