I'm trying to write a program to play the game Connect-N, which is basically Connect-4 but the user determines the size of the board (it is not necessarily square) and the number of consecutive pieces to win (which can be greater than the size of the board - if the board is 3x3, the user could specify that you need 4 pieces to win, and my code has to play out the game to a tie since it's impossible to win). I'm checking for 4 cases: horizontal win, vertical win, left diagonal win, and right diagonal win. I wrote out the logical steps to actually check for the wins, and then tried to turn that into code. However, when I run the actual program, it keeps returning that it's a tie game even when a player has won, which can only be reached if all 4 win functions return false. Can anyone spot the error in my code?

Here is my code:
(just for reference, the variable pieces represents either an X or O)

Horizontal win:

```
bool horizontalWin(char **board, const int numRows, const int numCols, const char blankSpace, const int numToWin, const char pieces) {
  int match = 0;

  if (numCols < numToWin) {
    return false;
  }
  else {
    for (int row = 0; row < numRows; ++row) {
      for (int col = 0; col <= numCols - numToWin; ++col) {
        for (int k = 0; k < numToWin; ++k) {
          if (board[row][col + k] != pieces) {
            match = 0;
          }
          else {
            ++match;
            if (match == numToWin) {
              return true;
            }
          }
        }
      }
    }
  }
  return false;
}

```

Vertical win:

```
bool verticalWin(char **board, const int numRows, const int numCols, const char blankSpace, const int numToWin, const char pieces) {
  int match = 0;

  if (numRows < numToWin) {
    return false;
  }
  else {
    for (int col = 0; col < numCols; ++col) {
      for (int row = 0; row <= numRows - numToWin; ++row) {
        for(int k = 0; k < numToWin; ++k){
          if (board[row + k][col] != pieces) {
            match = 0;
          }
          else {
            ++match;
            if (match == numToWin) {
              return true;
            }
          }
        }
      }
    }
  }
  return false;
}

```

Left diagonal:

```
bool leftDiagonalWin(char **board, const int numRows, const int numCols, const char blankSpace, const int numToWin, const char pieces) {
  int match = 0;

  if (numCols < numToWin || numRows < numToWin) {
    return false;
  }
  else {
    for (int row = 0; row <= numRows - numToWin; ++row) {
      for (int col = 0; col <= numCols - numToWin; ++col) {
        for (int k = 0; k < numToWin; ++k) {
          if(board[k][k] != pieces) {
            match = 0;
          }
          else {
            ++match;
            if (match == numToWin) {
              return true;
            }
          }
        }
      }
    }
  }
  return false;
}

```

Right diagonal:

```
bool rightDiagonalWin(char **board, const int numRows, const int numCols, const char blankSpace, const int numToWin, const char pieces) {
  int match = 0;

  if (numCols < numToWin || numRows < numToWin) {
    return false;
  }
  else {
    for (int row = numRows - 1; row >= numRows - numToWin; --row) {
      for (int col = 0; col <= numCols - numToWin; ++col) {
        for (int k = 0; k < numToWin; ++k) {
          if (board[numRows - 1 - k][col + k] != pieces) {
            match = 0;
          } else {
            ++match;
            if (match == numToWin) {
              return true;
            }
          }
        }
      }

    }
  }
  return false;
}

```

Edit: this is the function I use to create the board:

```
char** createBoard(const int numRows, const int numCols, const char blankSpace) {
  char** board = (char**) malloc(numRows * sizeof(char*));
  for (int row = 0; row < numRows; ++row) {
    board[row] = (char*) malloc(numCols * sizeof(char));
    for (int col = 0; col < numCols; ++col) {
      board[row][col] = blankSpace;
    }
  }
  return board;
}

```