Hello,
i'm having some problems to solve this incompleted tic-tac-toe code.
After the compilation you can see that are some strange simbols in the table.
Can someone tell me what is happening ?
if i change screen[3][3] to screen[4][4] the problem is "solved" but the true is that the problem is hide in screen[4][4]
Neither the first index nor the second index can have value equal to 3. The acceptable range for indexes is [0, 2]. So for example this code is invalid. You are accessing memory beyond the array
Arrays start at zero, so the declaration of screen[3][3] has valid subscripts 0,1,2.
So the statement screen[3][3] is out of range for the array, and prints garbage values.
Apart from that, you should get out of the habit of using global variables. Declare them in main(), and pass them to any function that needs them. Also check out the use of references.
When using arrays, it is much easier to use nested for loops to interact with them.
1 2 3 4 5 6 7 8 9 10 11
constint SIZE = 3;
char Board[SIZE][SIZE];
// initialise the board to blank spaces
for(int Row = 0; Row < SIZE; Row++) {
for(int Col = 0; Col < SIZE; Col++) {
// print Board[Row][Col] and formatting here
}
}
Have you seen the tutorial & reference section on this site? Links to them are at the top left of this page.
Sure, thank you for the tips, I really going to use it right now.
Actually I have not seen it. Yesterday I asked some guys for some kind of forum where i could ask for some help and one of the guys told me about this site.
Right now I'm for sure going to see the tutorials and references.