Here is my code. I assume this is a small error that I have made in one of my functions. It started happening after I implemented the "get_int" function and the "check_row" function. Any help or other suggestions would be greatly appreciated.
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
void get_int(int&, int&);
void check_row(char**, int&, int&, int&);
void print_board(char **, int, int);
void initialize_board(char **, int, int);
void update_board(char**, int, int, int&);
void delete_board(char**, int);
void check_args(int, char**, int&, int&, int&);
void reprompt_args(int&, int&, int&);
void error();
using namespace std;
int main(int argc, char** argv) {
int cols, rows, players, player = 1, col;
check_args(argc, argv, cols, rows, players);
char** board = new char*[rows];
for (int i = 0; i < rows; i++)
board[i] = new char[cols];
initialize_board(board, cols, rows);
get_int(col, cols);
check_row(board, col, rows, player);
print_board(board, cols, rows);
//update_board(board, cols, rows, col);
delete_board(board, rows);
return 0;
}
void get_int(int& col, int& cols) {
while((!(cin >> col)) || (col > cols)) {
error();
}
}
void check_row(char** board, int& col, int& rows, int& player) {
int a = 0;
if ((board[col-1][a]!=0) && (a < rows)) {
a++;
check_row(board, col, rows, player);
}
else if(player == 1 && a < rows) {
board[col-1][a] == 'X';
a=0;
}
else if (player == 2 && a < rows) {
board[col-1][a] == 'O';
a=0;
}
else {
cout << "Invalid Row Try Again!" << endl;
a=0;
player++;
}
}
void print_board(char ** board, int cols, int rows) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (i % 2 == 0 && j % 2 == 0)
cout << "|\033[30;47m " << board[i][j] << " ";
else if (i % 2 == 1 && j % 2 == 1)
cout << "|\033[30;47m " << board[i][j] << " ";
else
cout << "|\033[0m " << board[i][j] << " ";
cout << "\033[0m";
}
cout << endl;
}
}
void delete_board(char** board, int rows) {
for(int i = 0; i < rows; i++)
delete[] board[i];
delete[] board;
}
void update_board(char** board, int cols, int rows, int& col) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++)
board[i][j] = 'X';
}
print_board(board, cols, rows);
}
void initialize_board(char ** board, int cols, int rows) {
for (int i = 0; i < cols; i++)
cout << " " << (i + 1) << " ";
cout << endl;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (i % 2 == 0 && j % 2 == 0)
cout << "|\033[30;47m " << board[i][j] << " ";
else if (i % 2 == 1 && j % 2 == 1)
cout << "|\033[30;47m " << board[i][j] << " ";
else
cout << "|\033[0m " << board[i][j] << " ";
cout << "\033[0m";
}
cout << endl;
}
cout << endl;
}
void check_args(int argc, char** argv, int& cols, int& rows, int& players) {
int arg;
for(int i = 1; i < argc; i++) {
if (atoi(argv[i]) == 0) {
cout << "Invalid Argument #" << i << "!" << endl;
arg = 0;
}
}
if ((atoi(argv[1]) > 2) || (atoi(argv[2]) > 20) || (atoi(argv[3]) > 20) || (argc != 3))
arg = 0;
if (arg == 1) {
players = atoi(argv[1]);
rows = atoi(argv[2]);
cols = atoi(argv[3]);
}
else {
reprompt_args(players, rows, cols);
}
}
void reprompt_args(int& players, int& rows, int& cols) {
cout << "Invalid Command Line Arguments!" << endl << endl;
cout << "Enter Players: ";
while((!(cin >> players)) || (players > 2) || (players < 1)) {
error();
}
cout << "Enter rows: ";
while((!(cin >> rows)) || (rows > 20) || (rows < 2)) {
error();
}
cout << "Enter cols: ";
while((!(cin >> cols)) || (cols > 20) || (cols < 2)) {
error();
}
}
void error() {
cout << "Error! Enter a valid input: " << endl;
cin.clear();
cin.ignore(1024, '\n');
}