2
I have two files .txt
, and each has a 2x8 matrix.
I need to read these files and compare them, row by row, and when the line of both is equal, add to a counter.
However, the problem I’m facing is this: after reading both matrices, as I said, I need to compare them, however, the algorithm compares all values, rather than comparing only line with line.
Follow the code I made:
#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;
}