prog_avancee_C/TP2/part_1/copy.c
2024-10-22 13:03:17 +02:00

36 lines
696 B
C

#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: copy <file1> <file2>\n");
exit(-1);
}
FILE * ogf = fopen(argv[1], "r");
if (ogf==NULL) {
perror("Error while opening file1");
}
FILE * tf = fopen(argv[2], "w+");
if (tf==NULL) {
perror("Error while opening file2");
}
fseek(ogf, 0, SEEK_END);
int ogf_size = ftell(ogf);
fseek(ogf, 0, SEEK_SET);
char * f = malloc(sizeof(char) * ogf_size);
fread(f, sizeof(char), ogf_size, ogf);
fwrite(f, sizeof(char), ogf_size, tf);
fclose(ogf);
fclose(tf);
return 0;
}