완성 된 보드를 확인하는 스도쿠 프로그램을 작성하려고합니다. 나는 다음과 같은 오류를 받고 있어요인수 '1'에 대해 'int *'를 'int * (*) [9]'로 변환 할 수 없습니다.
#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);
}
:
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]);
나는 무슨 일인지 모르겠어요 여기에 지금까지 내 코드입니다. 나는 여기와 다른 웹 사이트에서 비슷한 상황을 보았고 그들의 솔루션을 구현하려했지만 아무도 노력한 적이 없다. 누구든지 내가 변경할 필요가있는 것을 알아 내면 큰 도움이 될 것입니다.
P. is_col_ok() 함수와 is_square_ok() 함수는 is_row_ok() 함수와 매우 유사하므로 포함되지 않습니다.
P.P.S. 내 pthread 작성 기능을 살펴보고 내가 올바르게 작성했는지, 내가 바꿀 필요가 없는지 말해 줄 수 있다면
P.P. 당신이 추가 코드를 필요로하는 경우가
오류는 'board [9] [9]'가 'int'유형의 값으로 해석되기 때문에 발생합니다. 그래서 당신은 그것의 주소를 가져 와서'int', 일명'int * '에 대한 포인터를 갖습니다. 호출하려고하는 함수가 예상하는 매개 변수의 값 유형과 일치하지 않으므로 컴파일러 오류가 발생합니다. – user268396
is_row_ok (& board [9] [9]); - 당신은 그걸 어떻게 말하려고 했습니까? – AnT
http://stackoverflow.com/questions/8767166/passing-a-2d-array-to-a-c-function – stark