2
I want to create an array using pointer pointer, but I’m having difficulty passing the parameters. First I dynamically allocate the matrix using a function. And then I read. The program compiled, but when reading the values it stops. I think the error is in the parameter passage, but I can’t see.
int alocaMatriz(int **matriz, int lin, int col){
int i;
matriz=(int**)malloc(lin*sizeof(int*));
for(i=0;i<col;i++){
matriz[i]=(int*)malloc(col*sizeof(int));
}
}
void leMatriz(int **matriz, int lin, int col){
int i, j;
printf("\nDigite os valores: ");
for(i=0;i<lin;i++){
for(j=0;j<col;j++){
scanf("%d", &matriz[i][j]);
}
}
}
int main(int argc, char** argv) {
int lin, col;
int **matriz;
printf("Digite as dimensoes da matriz: ");
scanf("%d %d", &lin, &col);
alocaMatriz(matriz, lin, col);
leMatriz(matriz, lin, col);
mostraMatriz(matriz, lin, col);
return 0;
}