-
Notifications
You must be signed in to change notification settings - Fork 0
/
OS lab1.3.c
58 lines (50 loc) · 1.12 KB
/
OS lab1.3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
typedef enum {
fsc_ok,
fsc_invalid_num_arg,
fsc_error_input,
fsc_error_output
} function_status_code;
int copy(FILE* proto, FILE* post) {
char buff[BUFSIZ];
size_t ch = fread(buff, sizeof(char), BUFSIZ, proto);
while (ch > 0) {
fwrite(buff, sizeof(char), ch, post);
ch = fread(buff, sizeof(char), 1, proto);
}
return 0;
}
function_status_code input(int argc, char* argv[]) {
if (argc != 3) {
return fsc_invalid_num_arg;
}
FILE* input_f = fopen(argv[1], "rb");
if (input_f == NULL) {
return fsc_error_input;
}
FILE* output_f = fopen(argv[2], "wb");
if (output_f == NULL) {
return fsc_error_output;
}
copy(input_f, output_f);
fclose(input_f);
fclose(output_f);
return fsc_ok;
}
int main(int argc, char* argv[]) {
switch (input(argc, argv)) {
case fsc_ok:
printf("All is ok\n");
break;
case fsc_invalid_num_arg:
printf("Invalid number of arg\n");
break;
case fsc_error_input:
printf("Error input file\n");
break;
case fsc_error_output:
printf("Error output file\n");
break;
}
return 0;
}