Hello people, I have a small problem. I am creating a function that receives as parameters a double pointer. This function receives the parameter and assigns it dynamic memory. Once the memory is assigned, I call another function that assigns values to that pointer. But when doing the assignment of values gives me segmentation error, I suspect that the problem is in the passage of the pointers as a parameter, because when I do everything in the main and not in functions does not present problem, I pass the codes so someone can guide me.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define dim 100
void asignarMemoriaDinamica(double** A){
int i;
A=malloc(dim*sizeof(double*));
for(i=0;i<dim;i++){
A[i]=malloc(dim*sizeof(double));
}
}
void cargarA(double** A){
int i,j;
srand(time(NULL));
for(i=0;i<dim;i++){
for(j=0;j<dim;j++){
int test = rand()%200 -100;
A[i][j]=test; //al ejecutar esta linea da error
printf("%.2lf ",A[i][j]);
}
printf("%s","\n");
}
}
int main() {
double **A;
asignarMemoriaDinamica(A);
cargarA(A);
return 0;
}