Ok here is the program. I'm trying to put the user's move, either X or O in the array postion that they chose and display the board again with the X or O in that positon. It isn't working though.
Code:
#include <stdio.h>
#include <stdlib.h>
#define NUMBER_OF_SQUARES 9
char tic_tac_toe[NUMBER_OF_SQUARES]={'0', '1','2', '3', '4', '5','6', '7', '8'};
void print_board(char*tic_tac_toe);
void clear_board();
char get_user_character(char);
void user_move();
int main()
{
int use_move;
char choice;
char tic_tac_toe_board;
char user_representation;
clear_board();
print_board( tic_tac_toe);
get_user_character(choice);
user_move();
print_board(tic_tac_toe);
return 0;
}
void clear_board(void)
{
int i;
for (i = 0; i < 9; i++)
{
tic_tac_toe[i] = ' ';
}
}
void print_board(char *tic_tac_toe)
{
printf(" %c | %c | %c\n", tic_tac_toe[0], tic_tac_toe[1], tic_tac_toe[2]);
printf("----+---+----\n");
printf(" %c | %c | %c\n", tic_tac_toe[3], tic_tac_toe[4], tic_tac_toe[5]);
printf("----+---+----\n");
printf(" %c | %c | %c\n", tic_tac_toe[6], tic_tac_toe[7], tic_tac_toe[8]);
}
char get_user_character(char choice)
{
printf("play with X or play with O\n");
scanf("%c", &choice);
return (choice);
}
void user_move(void)
{
char choice;
static int i;
printf("enter what box number that you\n");
printf("would like to place you move in> \n");
scanf("%d",&i);
if (i < 0 || i > 8)
{
printf("invalid move\n");
}
else
tic_tac_toe[i] = choice;
}
my output is:
| |
----+---+----
| |
----+---+----
| |
play with X or play with O
X
enter what box number that you
would like to place you move in>
3
| |
----+---+----
| |
----+---+----
| |
Kinda wierd. can't figure out how to pass the X or O into the array and display it correctly.