Try to search your question here, if you can't find : Ask Any Question Now ?

Is there a reason why my array has multiple of the inputted values in my Tic Tac Toe game?

HomeCategory: stackoverflowIs there a reason why my array has multiple of the inputted values in my Tic Tac Toe game?
Avatarcraig asked 2 weeks ago

I’m creating a tictactoe game in C and my showBoard function seems to be outputting multiple “x’s” when going through one turn. Why is my array storing multiple of the same values?

I have tried initializing the array to whitespace and then outputting the rows and columns to verify that I’m only putting in what I think I am.

void showBoard(char board[][3]){
int rows,columns;
for(rows=0;rows<3;rows++){
    for(columns=0;columns<7;columns++){
        printf("%c",board[rows][columns]);
    }
    printf("n");
}
}
...
while(1){
    printf("Enter (x) or (o): n");
    scanf("%c",&input);
    printf("Enter row: n");
    scanf("%d",&rows);
    printf("Enter column: n");
    scanf("%d",&columns);
    game[rows][columns]=input;
    showBoard(game);
}

I expect for this to update only the row and column with an X or an O. Instead it is updated multiple rows and columns.

1 Answers
Best Answer
AvatarMannu answered 2 weeks ago
Your Answer

2 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com