-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
72 lines (55 loc) · 1.44 KB
/
client.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include "bignumber.h"
//#include <time.h>
int main(int argc, char* argv[]) {
//clock_t start, end;
//double cpu_time_used;
//start = clock();
BigNumber A, B, RES;
char operator;
FILE* file = fopen(argv[1], "r");
if (argc != 2) {
printf("Erro, sintaxe correta: %s filename\n", argv[0]);
return 1;
}
if (file == NULL) {
printf("Erro ao abrir o arquivo");
return 1;
}
FILE* out;
char* output = file_name(argv[1]);
out = fopen(output, "wr");
while((operator = fgetc(file)) != EOF){
ungetc(operator, file);
A = bignumber();
B = bignumber();
RES = bignumber();
read_input_file(A, file);
read_input_file(B, file);
fscanf(file, "%c\n", &operator);
switch (choose_operation(operator, A->sign, B->sign))
{
case 0:
subtract(A, B, RES);
break;
case 1:
add(A, B, RES);
break;
default:
multiply(A, B, RES);
break;
}
bignumber_print_file(RES, out);
bignumber_free(A);
bignumber_free(B);
bignumber_free(RES);
}
fclose(out);
fclose(file);
free(output);
//end = clock();
//cpu_time_used = ((double)(end - start)) / (CLOCKS_PER_SEC / 1000);
//printf("time: %.3fms\n", cpu_time_used);
return 0;
}