I have a struct being passed in as a void* pointer
void *find_queens(void *args) {
I tried to turn this pointer in a usable struct using this
struct queens_arg *data = (struct queens_arg *) args;
However, the array that is stored within this
struct queens_arg {
int board[64];
int focus_idx;
};
called board is now being corrupted and does not reflect the original values, does anyone knows why? Thanks!
More information here:
This is the start of the function:
void *find_queens(void *args) {
//vars
pthread_t thread1, thread2;
struct queens_arg *data = (struct queens_arg *) args;
int board[64];
copy_array(data->board, board);
print_board(data->board);
This is how it is called:
int board[64] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
};
struct queens_arg *args = malloc(sizeof (struct queens_arg));
args->focus_idx = 0;
copy_array(board,args->board);
(*find_queens)(&args);
When I print the array, I get this instead:
39456784 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Instead of 0 all the way. Which is weird.