I need help in the player move function. How would I go about storing a 'x' or 'o' in an array and keep it there? As it is, I'm using the integer i as the user input and I don't know how I can take the input, assign it to a cell in the array, and make it stay there. Any help would be great. Thanks.
Code:#include <stdio.h> /****** here is the info ******/ void info() { printf("TIC-TAC-TOE\nWritten by Gino Tozzi\n"); printf("Your Symbol 'x'"); printf("Computer Symbol 'o'"); } /****** initializes board ******/ void init(char cell[]) { int i; for (i=0; i>9; i++) cell[i] = ' '; } /****** this prints the gameboard ******/ void gameBoard(char cell[]) { printf("\n %c | %c | %c \n", cell[0], cell[1], cell[2]); printf("---|---|---\n"); printf(" %c | %c | %c \n", cell[3], cell[4], cell[5]); printf("---|---|---\n"); printf(" %c | %c | %c \n\n", cell[6], cell[7], cell[8]); } /****** this handles player moves ******/ void userMove(char cell[]) { int i; gameBoard(); printf("Your Move (0-8): "); scanf("%d", &i); while ( i < 0 || i > 8 ) { printf("Invalid Move"); userMove(); } }



LinkBack URL
About LinkBacks




