I recently wrote this program that displays (command-line program) a tic-tac-toe format to be played. I had started the program and wrote the function to print out the board with the specified occupied spots (an array). I tested it out, and I got a weird printout with numbers instead of the ' ' char or the 'O' char. Can you please take a look and tell me what's wrong?:
Thanks!Code:/**************************************************** TicTacToe -- a program to simulate the game * ****************************************************/ #include <stdio.h> /***Function Prototypes***/ void printbrd(int pieces[3][3]); int main() { int pieces[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}}; /**print out the board for first time viewing**/ printbrd(pieces); return 0; } void printbrd(int pieces[3][3]) { char lines[3][20] = {"( ) ( ) ( )", "( ) ( ) ( )", "( ) ( ) ( )"}; char space[3][3]; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (pieces[i][j] == 1) space[i][j] = 'O'; else if (pieces[i][j] == 0) space[i][j] = ' '; } j = -3; sprintf(lines[i], "(%c) (%c) (%c)", &space[i][j], &space[i][j+1], &space[j+2]); } /**print out the lines that are pre-configured to the right**/ printf("%s\n", lines[0]); printf("%s\n", lines[1]); printf("%s\n", lines[2]); }



LinkBack URL
About LinkBacks


