title: Read Matrix from file, give it to main
body: <p>I have a fairly simple program. It reads a matrix from a file that looks like this</p>
  
  <pre><code>4 4
  
  a b c d
  a b c d
  a b c d
  a b c d
  </code></pre>
  
  <p>and outputs it in the console. The program is working as intended: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main() {
  
    int n, m;
    ifstream myfile;
    myfile.open ("matrix.txt");
    myfile &gt;&gt; n &gt;&gt; m;
    char mat[n][m];
  
    for (int i = 0; i &lt; n; i++) {
      for (int j = 0; j &lt; m; j++) {
        myfile &gt;&gt; mat[i][j];
      }
    }
    for (int i = 0; i &lt; n; i++) {
      for (int j = 0; j &lt; m; j++) {
        cout &lt;&lt; mat[i][j];
      }
      cout &lt;&lt; endl;
    }
    return 0;
  }
  </code></pre>
  
  <p>Now this program is going to grow a lot, so I want to start using headerfiles and declare the functions external so that my main looks more like</p>
  
  <pre><code>int main() {
    readMat();
    printMat();
  }
  </code></pre>
  
  <p>My Problem is, I don't really know how to do this right. Where should I declare the matrix so that both functions can "see" it? I can't declare it globally as <code>char mat[n][m]</code> because I only know <code>n</code> and <code>m</code> inside <code>readMat()</code>. </p>
  
  <p>Or is my whole design flawed and there is much better way to do this?
  I would be grateful for every little tip.</p>
  
  <p>I have not worked with multiple files in c++ yet. </p>