2-dimensional char array

Hi, how do I make a 2-dimensional square array of single letters and make it output in a matrix-like fashion? This is what I have so far, but I can't find a way to input the letters into the array:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>
int main()
{
    int boardSize = 3;
    char board[boardSize][boardSize] = {'a','d','z'}, {'p','A','I'}, {'Q','G','v'};
    std::cout << std::setw(1);
    for (int i=0;i<=boardSize-1;i++)
    {
        for (int j=0;j<=boardSize-1;j++)
        {
            std::cout << board[i][j] << " ";
        }
    }
}


I also need all letters to be separated by a space and take up exactly the same amount of space. Am I doing it right? For example, the program above (if it worked) should output something like this:

1
2
3
a d z
p A I
Q G v


Please have a look at my code and point out my mistakes. Thanks!
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int main()
{
    const int boardSize = 3;
    char board[][boardSize] = { 'a', 'd', 'z', 'p', 'A', 'I', 'Q', 'G', 'v' };
    
    for ( int i = 0; i < boardSize; i++ )
    {
        for ( int j = 0; j < boardSize; j++ )
            std::cout << board[i][j] << ' ';
            
        std::cout << std::endl;
    }
}
Last edited on
Thank you for fixing it, that works perfectly! Not closing the thread yet in case I need some more help while trying to create a dungeon crawler.
Topic archived. No new replies allowed.