Please Help me with this function

I am trying to get this function to work for a Tic Tac Toe game that I have written. I think the problem is in computer_move function. I think I might be going beyond the array limit but I don't see it. I was thinking of trying a different kind of loop or maybe a different logic test. Please any ideas would be great!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  
string TicTac[3][3]=
{
{" "," "," "},
{" "," "," "},
{" "," "," "}
};
int comp_col[] ={1,0,2,2,0,1,0,2,1};
int comp_row[] ={1,0,2,0,2,0,1,1,2};


void computer_move()
{
    int up = 0, col, rows;
    do{
            comp_col[up] = col;
            comp_row[up] = rows;
            up++;
    }while(TicTac[rows][col] != "X" && TicTac[rows][col] != "O");
    TicTac[rows][col] = player;
    Check();
    turn();

}


Hello bpedigo,

Here is my feedback:
1. You are setting comp_col[up] to the value of col, it isn't defined. The same applies to rows. Therefore, these values at the memory locations for these variables are indepterminate. Try changing those to be set to some actual value before you use them.
Topic archived. No new replies allowed.