35 lines
676 B
C
35 lines
676 B
C
#include <stdlib.h>
|
|
#include <stdio.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], "a+");
|
|
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;
|
|
}
|
|
|