-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparator.c
65 lines (55 loc) · 1.01 KB
/
comparator.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
#include <stdio.h>
#include <stdlib.h>
int compararMatriz(char **argv)
{
FILE *a = fopen(argv[1], "r");
FILE *b = fopen(argv[2], "r");
int val1, val2, i = 0;
int scan1, scan2;
do{
scan1 = fscanf(a, " %d", &val1);
scan2 = fscanf(b, " %d", &val2);
if(val1 != val2)
{
printf("Different\n Element: %d\n", i);
return 0;
}
i++;
}while(scan1 == scan2 && scan1 != EOF);
if(scan1 != scan2)
{
printf("Different dimensions\n");
return 0;
}
printf("Euqal\n Checked elements: %d\n", --i);
return 1;
}
int verificarArgumentos(int argc, char **argv)
{
if(argc != 3)
{
printf("Invalid arguments\n");
printf("./comp arquivo1.txt arquivo2.txt\n");
return 0;
}
FILE *f;
if((f = fopen(argv[1], "r")) == NULL)
{
printf("File 1 does not exist\n");
return 0;
}
fclose(f);
if((f = fopen(argv[2], "r")) == NULL)
{
printf("File 2 does not exist\n");
return 0;
}
fclose(f);
return 1;
}
int main(int argc, char **argv)
{
if(verificarArgumentos(argc, argv))
compararMatriz(argv);
return 0;
}