In the exec I am developing, I try to pass a dynamically created array created with the malloc
function, but doing so compiles the pointer type as incompatible.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void substituiNegativos(int c, int mat[][c]){
int i, j;
for(i=0; i< 2; i++){
for(j=0; j< 2; j++){
if(mat[i][j] < 0){
mat[i][j] = abs(mat[i][j]);
}
}
}
for(i=0; i< 2; i++){
for(j=0; j<2; j++){
printf("%d ", mat[i][j]);
}
printf("\n");
}
}
int main()
{
int i, j, l, c;
printf("Numero de linhas: ");
scanf("%d", &l);
printf("Numero de colunas: ");
scanf("%d", &c);
int **mat = (int**)malloc(l * sizeof(int));
for(i=0; i<l; i++){
mat[i] = (int*)malloc(c * sizeof(int));
for(j=0; j<c; j++){
printf("Insira o numero: ");
scanf("%d", &mat[i][j]);
}
}
substituiNegativos(c, mat);
return 0;
}