Hi all,
I would like to ask for you help to correct the following code for me. I am trying to define a 2D int array, then pass it in a function. I got an error "error: a value of type "void *" cannot be used to "xx file", line 113". Here is my code:
Thx!!!!
I would like to ask for you help to correct the following code for me. I am trying to define a 2D int array, then pass it in a function. I got an error "error: a value of type "void *" cannot be used to "xx file", line 113". Here is my code:
Code:
.......
void fun(int**);
......
///////////////////////////////
int main(int argc, char** argv){
.......
//the following is line 113
int **distance = malloc(n*sizeof(int *)),**trace = malloc(n*sizeof(int *));
distance = trace = malloc(n * sizeof(int *));
for (i = 0; i < m; i++) {
distance[i] = trace[i] = malloc(m * sizeof(int));
}
.......
fun(distance);
}
//////////////////////////////
void fun(int **distance){
.....
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
distance[i][j]=distance[i][j]*2;
}
}
......
}
//////////////////////////////
Comment