Tic Tac Toe program

This is a discussion on Tic Tac Toe program within the C Programming forums, part of the General Programming Boards category; This is supposed to generate and print a tic tac toe program which is seeded by the user's input. It ...

Tic Tac Toe program

This is supposed to generate and print a tic tac toe program which is seeded by the user's input. It generates the tic tac toe board by using a variable which is assigned to randomly generate either a 1 or a 2, which is prints as X and Y. My problems currently are getting the function "validBoard" to work properly.

validBoard is supposed to check whether or not the board is valid by checking the sum of the 1s and 2s. If the sum is out of the range 15 to 12 then it is invalid. When I run, it says every board is invalid, even when they aren't.

I also need to make a subsequent function after validBoard (which I call winnerBoard), which needs to determine who won (if anyone). I was thinking it would be possible to do this using a bunch of if-else-if statements, but it would be really redundant. Do you know a better way I could do this?

(1) You could use for-loops to "condense" your row checks and your column checks.
(2) You could use auxiliary counters (maybe not so easy in this case; easier to do while actually playing the game) so that putting an X in the upper left corner might increment Xrow[0], Xcol[0], and Xdiag[0]. If any of the counters get to three, it's a win.

I've hit another snag now. What I'm trying to do is have a function called winnerBoard check to see which pattern, if any, won. Then it returns a variable called "win", which holds 0 if there is no winner, 1 if O wins, and 2 if X wins. I'm then trying to use "win" as an input parameter into my function printWinner. For some reason printWinner isn't taking the variable though, it always sees win as 0, even when winnerBoard sees at as 1.

(note: as of right now winnerBoard is only partially complete and just for 'O' winning)