My code prints out a wacked out version of a .txt file that displays a 20x20 table of characters and white spaces. How can i get the array to display properly as it does in the .txt. I can not use vectors or global variables. It can be done without those. The first two lines in the text are 20 and 20 to get the dimensions for the array.
ifstream inputFile;
int boardSizeRow;
int boardSizeCol;
inputFile.open("fileboard1.txt");
inputFile >> boardSizeRow;
inputFile >> boardSizeCol;
inputFile.get();
char gameBoard[20][20];
for (int row = 0; row < boardSizeRow; row++)
{
for (int col = 0; col < boardSizeCol; col++)
{
gameBoard[row][col] = inputFile.get();
}
}
for (int row = 0; row < boardSizeRow; row++) //////////////TO TEST PRINT
{
for (int col = 0; col < boardSizeCol; col++)
{
cout << gameBoard[row][col];
}
inputFile.get();
cout << endl;
}
return 0;
20
20
WWWWWWWWWWWWWWWWWWWW
W GO W W
W WW w S W
W W GW w W
WPW WW G W
WK W W
W W W W w w W
W WK W W
W SW U w w W
W
w G W
G w w W
D wwwww W
w D W
w w W w w W
ww w w w W
G w W
ww w S w W
WWW G W
WWWWWWWWWWWWWWWWWWWW