//loop through the 2d array
for(int i = 0; i <= boardsize; i++)
{
getline(fin, line);
for(int j = 0; j < boardsize; j++)
{
if(i != 0)
board[i][j] = (int)line[j];
}
line.clear();
}
needs to be
//loop through the 2d array
for(int i = 0; i < boardsize; i++) // note < instead of <=
{
getline(fin, line);
for(int j = 0; j < boardsize; j++)
{ // not I deleted if statement
board[i][j] = (int)line[j];
}
line.clear();
}
This is because arrays in C++ start at the index 0, so when you allocate an array of size three, as you do above with board = new int*[boardsize];
, the indices of this array will be 0, 1, 2, ... boardsize-1
, whereas your algorithm was using 1, 2, 3, ... boardsize
which will be an out of bounds access because you only have n blocks allocated and you are trying to access (modify, actually) block n + 1, which will result in a segmentation fault.
solved Why is my programming crashing [closed]