Im programming tic tac toe but the board is not showing numbers, and it is simply stating the winner without any input: (the win conditions are not complete, but it shouldnt matter).
1) I strongly recommend you start using a consistent indentation style. It will make your code easier to read, for us and for you. In particular, it will make the flow of control through your code a lot easier to see at a glance, helping you spot errors quickly.
2) Your problem is that you're declaring two variables called board. The first is a global variable, that you define at line 9. The second is a local variable in main, that you define at line 17. Within main, this local variable hides the global one.
The local array is the one you're initializing to contain numbers. The global array is never initialised. And it's the global one that's being used by moveIsValid(), showBoard() and whoWon().
You should avoid using global variables as much as possible. I'd advise sticking with the local one, and passing that as an argument into your other functions.
I had indentations, but when I paste it in it doesnt work.
edit: How would you recommend I use my char board array? I deleted the local one and pasted char board[10]= {' ', '1', '2', '3','4','5','6','7','8','9'}; in the global (instead of the other one).
Your global board should be initialized like this: char board[10]= {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
This way your showBoard() function prints out empty spaces instead of numbers.
@NZheadshot, i dont want empty spaces, I want numbers. It currently works as planned, but the removal of void main to int main gives me errors. So I put it back to void main.
How would you recommend I use my char board array? I deleted the local one and pasted char board[10]= {' ', '1', '2', '3','4','5','6','7','8','9'}; in the global (instead of the other one).
Um, I already gave you my recommendation:
MikeyBoy wrote:
You should avoid using global variables as much as possible. I'd advise sticking with the local one, and passing that as an argument into your other functions.
venros wrote:
the removal of void main to int main gives me errors. So I put it back to void main.
Assuming you actually changed your function to return something (because, obviously, if you define your function to have a return value, then you need to actually return something) then it shouldn't have caused an error. What error message did you get?
Nathan2222 is correct - main functions should always return an int.