Here in the code written below, when I am passing the two dimensional matrix( in this case it is nMatrix[][]
) , and in the function i\I am storing that into a double pointer. Then a problem is being created in accepting the elements of the array.
If I perform the same task using dynamic memory allocation and I keep the function syntax same, then it works perfectly. I want to know the reason, if anyone can help I will be thankful to him/her.
#include<stdio.h>
int inputMatrix(int **matrix , int row, int column)
{
int i, j, nonZero = 0;
printf("\n Enter the elements of the matrix : \n");
for(i=0; i<row; i++)
{
for(j=0; j<column; j++)
{
scanf("%d",&matrix[i][j]);
if(matrix[i][j]!=0)
nonZero++;
}
}
return nonZero;
}
int main()
{
int nMatrix[10][10], sMatrix[10][3], nr, nc, i, j, ch, nonZero;
// input the matrix in normal form
printf("\n Enter the number of rows : ");
scanf("%d",& nr);
printf("\n Enter the number of columns : ");
scanf("%d",&nc);
nonZero = inputMatrix(nMatrix,nr,nc);
return 0;
}
In eclipse it does not show an error, and in Code::Blocks it shows note which is
note: expected ‘int **’ but argument is of type ‘int (*)[10]’