I'm creating a tic tac toe game. This is what i want to do. get the user input (a number 1-9 the corresponds to the spaces on the board) and replace it with an X or O in the array tic_tac_toe. if they want an X in postion 4 how do i write the function to replace 4 with X? This is what i have so far
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();
void clear_board();
char get_user_character(char);
void user_move();
int main()
{
char choice;
int tic_tac_toe_board;
clear_board();
print_board();
get_user_character(choice);
tic_tac_toe[user_move-1]=user_representation;
return 0;
}
void clear_board(void)
{
int i;
for (i = 0; i < 9; i++)
{
tic_tac_toe[i] = ' ';
}
}
void print_board(void)
{
char tic_tac_toe[NUMBER_OF_SQUARES]={'0', '1','2', '3', '4', '5','6', '7', '8'};
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)
{
printf("enter what box number that you\n");
printf("would like to place you move in> \n")
scanf("%d",