The type of matriz
is a pointer (array) of integers. In this case, when you have the matriz[i]
operation, the value you have is an integer. The problem is that you are trying to access the index [j]
of this integer value.
You need to declare the matriz
parameter as an arrays array (or pointer pointer) to be able to access it via two indexes, as in the example below:
int contagemlinha(int ** matriz, int L, int C) {
int i, j, soma = 0;
for (i = 0; i < L; i++)
for (j = 0; j < C; j++)
soma += matrix[i][j];
return soma;
}
Another way to store two-dimensional arrays is to store it in a simple array, with elements of the first line followed by elements of the second, and so on. For example, the array
1 2 3 4
5 6 7 8
9 10 11 12
Can be stored in array
1 2 3 4 5 6 7 8 9 10 11 12
If this is your case then you just have to go through the array with an index:
int contagemlinha(int* matriz, int N)
{
int i, soma = 0;
for(i = 0; i < N; i++)
soma += matriz[i];
return soma;
}