Programming Tic Tac Toe

0 Reynaldo Gunawan · June 13, 2015
For my next project, i am asked to create Tic Tac Toe in C. The only clue that i got is that i need 3-dimensional array, as the users will put in the number of column and row to indicate which box they want to play. 

The question also says that i need to prove whether the box is already full or whether one of the player has his/her symbol three times in a line, well everyone knows Tic Tac Toe.

I know that i need a tremendous amount of functions to make this program, but i don't even know where to start and which and how many variables i would need. I've created the structure of the game without the number like the photos below, but that's only like 1/1000 done of what i need to do. I am so screwed...

If someone has any ideas, please let me know. I'm not expecting a whole complete program, as i would not learn as much from it anyway. I appreciate your replies.

Example of the format:


Post a Reply


- page 1
Oldest  Newest  Rating
0 c student · June 13, 2015
why do you need a 3d array?
+2 Alan Johnson · June 13, 2015
You certainly don't need a 3D array, you don't even need a 2D array for that matter.

I would break the project down into smaller parts. For tic-tac-toe you probably want functions for the following:

  • Get input from the user for where to move

  • Error check the input to make sure nobody has already played in that position

  • Make a move (put X or O in a cell)

  • Switch to the other player's turn

  • Check if a player has won by analyzing the cells in vertical, horizontal and diagonal directions.

  • Print the game to the console (seems like you're already on with that)

0 Jonas Meise · June 13, 2015
Well I just made a tic tac toe in java.
Don't know if you know java but I can show you the code if you want so you could try recreate something similar with whatever programming language you have to use.
Do you think that would help?
0 Reynaldo Gunawan · June 13, 2015
@c_student @AlanJohnson I thought when we deal with matrix, 3d array is needed...? Well i actually have no clue, I haven't actually used it until now. I used two for-loops to make the structure of the game. Specific thanks to Alan for categorizing the needed functions.

@JonasMaise anything at all would definitely help me right now, cause i'm basically screwed :P. Welll, there should be similarities between Java and C that i might be able to recognize, but are you okay with that though?
+4 Jonas Meise · June 13, 2015
Ye I'm okay with it^^ I started writing that tic tac toe when I saw your post because I wanted to know if I was able to do it with java^^

I tried to comment the code so you understand  what I have done where and why^^ Hope it's useful to you :)

Here is what the program would look like if you executed it:

0 Jonas Meise · June 13, 2015
the places where you see numbers are just buttons I didn't click yet.
+1 Alan Johnson · June 14, 2015
Wrote a version in C for you. I've left comments in the code but just ask if you don't understand anything.

The formatting is weird on here so I've put it on pastebin:
0 Reynaldo Gunawan · June 14, 2015
@JonasMeise well it didn't seem for you to take a long time to make the whole program :P Gosh, when can i be like that... Thank you once again. Though i have to make some connections to C, it's still relatively understandable even for me. Phew i know something...

@AlanJohnson wow thank you! I really appreciate it! I will definitely ask questions since i'm still a noob. 

Guys, i'm really thankful for what you're doing, but isn't this a bit too much? Creating the whole program and all haha i mean if you guys enjoy it, then it's fine. I feel like i'm burdening the media :P or maybe it's just me...
0 Jonas Meise · June 14, 2015
Hehe :P 
Well the reason I like helping out with such things mainly is because I get better through practice^^ The project I had before this was a calculator and then I ran out of ideas what to program so the idea with tic tac toe seemed good to me :P
0 Reynaldo Gunawan · June 15, 2015
@AlanJohnson may i ask you questions on your code? This might be beginner's questions, but i don't quite get how the function make_move (Line 50) work. And I'm having difficulties understanding the code inside the while-loop (Line 116). Can you please explain a little bit more, if you don't mind.

I don't know why i put the line number there, i mean it's your own code.




One of the most popular languages of all time.

Bucky Roberts Administrator