and in given code, have these values (unchangeable code):
#ifndef board_h #define board_h #define board_width 10 #define board_height 10 typedef enum cell { empty, //0 blocked, //1 player //2 } cell; #define empty_output " " cell board_1[board_height][board_width]; cell board_2[board_height][board_width]; void initialiseboard(cell board[board_height][board_width]); void displayboard(cell board[board_height][board_width]);
i have tried writing initialiseboard() in many ways like:
void initialiseboard(cell board[board_height][board_width]) { int i, j; int *temp = null; ( = 0; < 10; i++) (j = 0; j < 10; j++) board[i][j] = empty; } void initialiseboard(cell board[board_height][board_width]) { int i, j; int *temp = null; ( = 0; < 10; i++) (j = 0; j < 10; j++) { if (i == 0 && j == 0) { *temp = empty; board[0][0] = temp; } else board[i][j] = empty; } }
because know first cell in board @ [0][0] pointer, tried many ways referenced value return address. please have @ code below , suggest me approach. thank much!
void displayboard(cell board[board_height][board_width]) { int i, j; (i = 0; <= 10; i++) { if (i == 0) { printf("\t|%s|", empty_output); (j = 0; j < 10; j++) printf("%d|", j); printf("\n"); } else { (j = 0; j <= 10; j++) { if (j == 0) printf("\t|%d|", - 1); else { char* c; /*unsigned *p = &board[0][0]; if (i == 1 && j == 1) c = (*p == empty) ? empty_output : "?";*/ if (i == 1 && j == 1) c = (board[0][0] == empty) ? empty_output : "?"; else c = (board[i - 1][j - 1] == empty) ? empty_output : "?"; printf("%s|", c); } } printf("\n"); } } printf("\n%d\n", board[0][0]); }
at [0][0], returns address.
board[0][0]
base address of 2d array , printing base address of 2d array if want print value @ address should use '*'
shows value @ address in case should use *((board+0)+0)
can try , let me know if there issue :)
Comments
Post a Comment