I have two files .txt
, and each has a 2x8 array.
I need to read these files and compare them, line by line, and when the line of both is equal, add to a counter.
However, the problem I am facing is this: after reading both arrays, as I said, I need to compare them, but the algorithm compares all values, rather than comparing only row-by-row.
Here is the code I did:
#include <stdio.h>
#include<stdlib.h>
#define Lin 8
#define Col 2
int main(){
int i, j, cont_pontos_regra_um=0, resultado[Lin][Col], partic1[Lin][Col], cont=0;
FILE *arq;
arq=fopen("resultado.txt", "r");//abertura e scaneiamento do resultado.txt
for(i=0;i<Lin;i++){
for(j=0;j<Col;j++){
fscanf(arq,"%d ", &resultado[i][j]);
printf("%d ", resultado[i][j]);
}
}
fclose(arq); //fechar arquivo
arq=fopen("partic1.txt", "r");//abertura e scaneiamento do resultado.txt
for(i=0;i<Lin;i++){
for(j=0;j<Col;j++){
fscanf(arq,"%d ", &partic1[i][j]);
}
}
fclose(arq); //fechar arquivo
for(i=0;i<Lin;i++){
for(j=0;j<Col;j++){
if(partic1[i][j]==resultado[i][j]){
cont_pontos_regra_um++;
}
}
}
//printf("%d", cont_pontos_regra_um);
return 0;
}