Post the code. However, the error you are getting in your array is that you're probably trying to assign " " rather than ' ' for a single character.
You can also use memset ( variable, ' ', size ); or if you are using C++ and the string class you, you can initialize it with a character and a length to fill it with.
(ie:
string str7 (10,'A');
Thanks for the single quote tip. That solved one of the problems. This is actually a larger program that is supposed to play tic-tac-toe. I have commented out most of the program in order to solve problems one piece at a time. Anyways, here is the code.
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
void draw(char, int, int);/*
void assign(const string, int, string, int, string, int);
void test(const string, int, int, bool);
*/
int main()
{
//string ans = " ";
//while (ans != "y")
//{
//Declare and initialize the array
char empty = ' ';
const int columns = 3;
const int rows = 3;
char tictac[rows][columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
tictac[i][j] = empty;
}
}
int count = 1;
bool done = false;
cout << "Let's play tic-tac-toe!" << endl;
draw(tictac, rows, columns);
/*
while (count < 10)
{
test(tictac, rows, done);
if (!done)
{
if (count % 2 != 0)
{
int col = 0;
int row = 0;
string colpick;
int rowpick;
cout << "Player X. " << endl;
cout << "Please enter the column for your move(a, b, or c): ";
cin >> colpick;
cout << "Please enter the row for your move(1, 2, or 3): ";
cin >> rowpick;
assign(tictac, rows, colpick, rowpick, "X", count);
}
else
{
int col = 0;
int row = 0;
string colpick;
int rowpick;
cout << "Player O. " << endl;
cout << "Please enter the column for your move(a, b, or c): ";
cin >> colpick;
cout << "Please enter the row for your move(1, 2, or 3): ";
cin >> rowpick;
assign(tictac, rows, colpick, rowpick, "O", count);
}
draw(tictac, rows);
}
}
cout << "Would you like to play again? ";
cin >> ans;
}
*/
return 0;
}
/*
void assign(const string v[][3], int size, string colpick, int rowpick, string play, int& count)
{
int col;
int row;
if (colpick == "a")
col = 0;
else if (colpick == "b")
col = 1;
else
col = 2;
if (rowpick == 1)
row = 0;
else if (rowpick == 2)
row = 1;
else
row = 2;
if (v[col][row] != " ")
cout << "That square is already taken. Please chose another.";
else
{
v[col][row] = play;
count++;
}
}
*/
void draw(char v[][3], int size)
{
cout << endl;
cout << endl;
cout << " " << v[0][0] << " | " << v[0][1] << " | " << v[0][2] << " " << endl;
cout << "---+---+---" << endl;
cout << " " << v[1][0] << " | " << v[1][1] << " | " << v[1][2] << " " << endl;
cout << "---+---+---" << endl;
cout << " " << v[2][0] << " | " << v[2][1] << " | " << v[2][2] << " " << endl;
cout << endl;
cout << endl;
}
/*
void test(const string v[][3], int size, bool& done)
{
if ((v[0][0] == v[1][0] && v[1][0] == v[2][0]) && v[0][0] != " ")
{
cout << "****You win!*****";
done = true;
}
if ((v[0][1] == v[1][1] && v[1][1] == v[2][1]) && v[0][1] != " ")
{
cout << "****You win!*****";
done = true;
}
if ((v[0][2] == v[1][2] && v[1][2] == v[2][2]) && v[0][2] != " ")
{
cout << "****You win!*****";
done = true;
}
if ((v[0][0] == v[0][1] && v[0][1] == v[0][2]) && v[0][0] != " ")
{
cout << "****You win!*****";
done = true;
}
if ((v[1][0] == v[1][1] && v[1][1] == v[1][2]) && v[1][0] != " ")
{
cout << "****You win!*****";
done = true;
}
if ((v[2][0] == v[2][1] && v[2][1] == v[2][2]) && v[2][0] != " ")
{
cout << "****You win!*****";
done = true;
}
if ((v[0][0] == v[1][1] && v[1][1] == v[2][2]) && v[0][0] != " ")
{
cout << "****You win!*****";
done = true;
}
if ((v[0][2] == v[1][1] && v[1][1] == v[2][0]) && v[0][2] != " ")
{
cout << "****You win!*****";
done = true;
}
}
*/