Problems in reading and organizing a matrix in C

2

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;
}
    
asked by anonymous 23.06.2018 / 19:37

1 answer

0

In this section:

for(i=0;i<Lin;i++){
    for(j=0;j<Col;j++){
        if(partic1[i][j]==resultado[i][j]){
            cont_pontos_regra_um++;

Do this:

for(i=0;i<Lin;i++){
    int linhas_iguais = 1; // a principio sao iguais
    for(j=0;j<Col;j++){
        if(partic1[i][j]!=resultado[i][j]){
            linhas_iguais = 0; // sao diferentes!
            break;
        }
    }
    if(linhas_iguais)
        cont_pontos_regra_um++;
}
    
23.06.2018 / 19:55