0

I have a would like help regarding passing a 2d dynamically allocated array to a function.

My problem arises when I declare a 2d array for use in a thread so that I can multithread.

In my Main file:

int **prod = (int*)malloc(k * sizeof(int*));
for(int i = 0; i < k; i++){
   prod[i] = (int*)malloc(m * sizeof(int));
}

in my thread.c file:

typedef struct threadParam{
   int number, paramK, paramN, paramM;
   int paramLeft[2][3];
   int paramRight[3][2];
   int indexArray[2];
   int **product;
} threadParam;

void function(int noThread, int k, int n,
  int m, int left[][n], int right[][m], int prod[][m]){

}

I initialize prod with all zeros in main before passing it as a parameter to function but end up getting what I can assume is memory addresses in the elements of prod.

printed:

for(int i = 0; i < k; i++){
    for(int j = 0; j < m; j++){
        printf("MM%d ", prod[i][j]);
    }
}

output: MM11935792 MM0 MM11935824 MM0

I'm attempting to use threads later in order to write to the memory pointed to by prod in my main function.

Initializing the 2d array to 0s: **prod = (int) {0};

0 Answers0