title: c style string and dynamic allocation in c++
body: <p>I must implement a bunch of methods that allocates, modify and free a 2D array of c-style string. I cannot use string nor vectors nor any stl container.</p>
  
  <p>getNewMat :</p>
  
  <pre><code>char*** getNewMat(int w, int h){
      char*** newMat = new char**[h];
      for(int i = 0 ; i &lt; h ; i++){
          newMat[i] = new char*[w];
          for(int j = 0 ; j &lt; w ; j++)
              newMat[i][j] = NULL;
      }
      return newMat;
  }
  </code></pre>
  
  <p>fillMat</p>
  
  <pre><code>void fillMat(char***mat, int x, int y, char* newEl){
      mat[y][x] = newEl; //this will produce a segfault (even with good index)
  }
  </code></pre>
  
  <p>showMat :</p>
  
  <pre><code>void showMat(char*** mat, int w, int h){
      for(int i = 0 ; i &lt; h ; i++){
          for(int j = 0 ; j  &lt; w ; j++)
              cout &lt;&lt; mat[i][j];  
      }
      cout &lt;&lt; endl;
  }
  </code></pre>
  
  <p>so, can anyone please tell me what's wrong with this?</p>