Hi Jim,
thank you for your quick answer.
So, I used the changes you have proposed and the files are now
main.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "func2.c"
int main(){
int num_veins[NN];
int **veins;
int i;
network_construction(&veins, num_veins);
printf("\n%d\n", veins[2][2]);
for (i = 0; i < NN; i++) {
free(veins[i]);
}
free(veins);
return 0;
}
and func2.c:
Code:
#define NN 20
void network_construction(int ***veins, int *num_veins){
int i, j;
for(i=0;i<NN;i++){
num_veins[i] = NN/2;
}
*veins = malloc(NN * sizeof(*veins));
for (i = 0; i < NN; i++) {
*veins[i] = malloc(num_veins[i] * sizeof(**(veins[i])));
}
for (i = 0; i < NN; i++) { for (j = 0; j<num_veins[i];j++) { *veins[i][j] = -1; } }
return;
}
I build the codes reading stuff and taking examples on the Internet, my knowledge about pointers is not very broad, so I do not know exactly what is going on. You tell me that Segmentation is due to malloc call, but if I comment those lines in func2.c, and main.c only calls the function, the error is still there, so my guess is that I'm doing something wrong in the definition of network_construction, but I do not what.
What can I do ?