-2
How do I make, in C, a code that compares whether the line responses of an array are equal to the line of an array? Follows the question:
Follow the code I have:
#include <stdio.h>
int main()
{
char ma[5][10] = {'a','b','c','d','d','c','b','a','b','b','d','a','d','c','b','a','b','b','d','a',
'd','d','c','b','a','b','b','d','a','d','b','d','a','d','c','b','a','b','b','d','c','d','d','c',
'b','a','b','b','d','a'}, letter;
char gab[10] = {'a','b','c','d','a','b','c','d','b','b'};
int resultado[10], r, l, soma = 0;
//Corrigindo
for(r = 0; r < 5; r++){
for(l = 0; l < 10; l++){
if(ma[r][l] == gab[l]){
soma++;
}
resultado[r] = soma;
}
}
printf("Resultados\n\n");
for(r = 0; r < 5; r++){
printf("Aluno %d: %d\n", r+1, resultado[r]);
}
return 0;
}
This answers your question? Compare a char vector?
– Rebeca Nonato
https://answall.com/questions/247225/como-comparar-vetores-em-c
– Rebeca Nonato
https://answall.com/questions/390538/como-comparar-uma-posi%C3%A7%C3%A3o-da-string-com-um-character-c
– Rebeca Nonato
I believe that in your section "Correcting" you must reset the accumulator
soma
for each liner
otherwise it will not make sense what will store inresultado
.for(r = 0; r < 5; r++){ soma = 0; for(l = 0; l < 10; l++){ if(ma[r][l] == gab[l]){ soma++; } resultado[r] = soma; } }
– anonimo
It didn’t work. After doing this he reset all the results. I tested tbm before the r FOR and after l. No results.
– Rafael S.
Here https://ideone.com/PDDeaK worked.
– anonimo