User defined matrix of chars
<p>From user input such as:</p>

<pre><code>&gt;~d
alg
^%r
</code></pre>

<p>what would be the best way to create a square char matrix with each of the entered values assigned to the corresponding element? e.g. in this case charArray[0][0] would be '>' and charArray[2][1] would be '%' etc.</p>

<p>I tried the following using getchar(); however, I was having all kinds of problems with the '\n' that was left behind and figured there is probably an entirely different way of effecting this that was much better.</p>

<pre><code>char matrix[MAX][MAX];
char c;
int matSize;

std::cin &gt;&gt; matSize;

for (int i = 0; i &lt; matSize; ++i)
    {
        int j = 0;

        while ((c = getchar()) != '\n')
        {
            matrix[i][j] = c;
            ++j;
        }
    }
</code></pre>
