c++ - Initializing an array works fine, but when trying to print it back out it prints an extra column and an unexpected character -


so compiles without problem. problem i'm having when prints console, there column , strange ascii character in lower right corner. if try lessen size of array, can't initialize 9 elements anymore- , have have 9 elements make tic tac toe board. thought off 1 error, if so, can't figure out how fix it. i've read quite few of "tic tac toe" similar questions, don't seem having same issue.

#include <iostream>  using namespace std;  int main () { int countrow, countcol, play=1, subscript1, subscript2; int array_rows = 3, array_cols =3; char board [3][3] = {{42, 42,42}, {42, 42,42}, {42, 42,42}}; char input; while(play>0) {     for(countrow = 0; countrow<array_rows; countrow++)     {         for(countcol=0; countcol<array_cols; countcol++)         {             cout<<board [countrow][countcol];         }         cout<<board[countrow][countcol];         cout<<endl;     } cout<<"player 1, enter mark using row column coordinate system.\n"; cin>>subscript1>> subscript2; subscript1+=1; board[subscript1][subscript2] = 88; cout<<"player 2, enter mark using row column coordinate system.\n"; cin>>subscript1>> subscript2; board[subscript1][subscript2] = 79; } system("pause"); return 0; } 

here problem:

for(countrow = 0; countrow<array_rows; countrow++) {     for(countcol=0; countcol<array_cols; countcol++)     {         cout<<board [countrow][countcol];     }     cout<<board[countrow][countcol];      //^^^^^this 1 redundant , accessing invalid memory block     //^^^^^^ countcol out of bound     cout<<endl; } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -