I'm trying to write a sudoku program that verifies a completed board. Here is my code so far:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <pthread.h>
using namespace std;
int *board[9];
int row, col;
void is_row_ok(int* board[9][9]);
void is_col_ok(int* board[9][9]);
void is_square_ok(int* board[9][9]);
int main()
{
for (int i = 0; i < 9; ++i)
{
board[i] = new int[9];
}
string line;
ifstream myFile("Testfile1.txt");
for (int row = 0; row < 9; ++row)
{
string line;
getline(myFile, line);
stringstream iss(line);
cout << endl;
for (int col = 0; col < 9; ++col)
{
string val;
getline(iss, val, ',');
if (!iss.good())
break;
stringstream convertor(val);
convertor >> board[row][col];
cout << board[row][col] << " ";
}
}
is_row_ok(&board[9][9]); //<-- error happens here
pthread_create(thread1, NULL, is_row_ok, board[9][9]);
//pthread_create(thread1, NULL, is_col_ok, board[9][9]);
//pthread_create(thread1, NULL, is_square_ok, board[9][9]);
cout << endl;
return 0;
}
void is_row_ok(int board[9][9])
{
int element_count = 0;
char element_value;
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
element_count = 0;
element_value = board[i][j];
if (element_value != ' ')
{
for (int k = 0; k < 9; ++k)
{
if (board[i][k] == element_value)
element_count++;
}
}
if (element_count >= 2)
{
cout << "Row " << i << " is invalid." << endl;
}
else
{
cout << "Row " << i << " is valid." << endl;
}
}
}
//pthread_exit(NULL);
}
I'm getting the following error:
attempt.cpp:45:24: error: cannot convert ‘int*’ to ‘int* (*)[9]’ for argument ‘1’ to ‘void is_row_ok(int* (*)[9])’
is_row_ok(&board[9][9]);
I'm not sure what's going on. I've looked at a bunch of similar situations on here and on other websites and I've tried to implement their solutions but none have worked. If anyone could please help me figure out what I need to change that would be greatly appreciated.
P.S. the functions is_col_ok() and is_square_ok() are very similar to the is_row_ok() function which is why they are not included.
P.P.S. if you could also take a look at my pthread creation function and tell me if I have done it correctly and if not what I need to change
P.P.S. if you need any additional code please don't hesitate to ask for it