title: C++ char/string reading problem
body: <p>Again, I'm trying to make a simple program. It will read some kind of board, at the size of RxC. Each items on the board are letters, separated with spaces. This is a sample board:  </p>
  
  <p>A B C<br>
  D E F<br>
  G H I  </p>
  
  <p>After that, it will read an integer N, and for next N lines, read a string and process them one by one based on the given board. But now, I'm facing a problem with how to read them. Here is the code :  </p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int r,c,el; char **arr;
  
  int main()
  {
      char *tes;
      int n;
  
      //start reading the puzzle
      cin &gt;&gt; r &gt;&gt; c; el=r;
      cout &lt;&lt; el &lt;&lt; endl;
      arr = new char * [3*(r+c)-6];
      for(int i=0;i&lt;r;i++)
      {
          arr[i] = new char[c+1];
          for(int j=0;j&lt;c;j++) cin &gt;&gt; arr[i][j];
          arr[i][c] = '\0';
      }
      for(int i=0;i&lt;el;i++) cout &lt;&lt; arr[i] &lt;&lt; endl;
  
      cin &gt;&gt; n;
      while(n&gt;0)
      {
          n--;
          cin &gt;&gt; tes;
          cout &lt;&lt; tes &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>I don't know what's wrong with this, it's seems OK to me. However, it always get runtime errors. I'm using latest MinGW and gdb debugger. On gdb I saw something like </p>
  
  <blockquote>
    <p>"received signal SIGSEGV. Segmentation
    fault"</p>
  </blockquote>
  
  <p>, and an 0xC0000005 error. I really have no idea what's going on here. I've tried both iostream(cin&amp;cout) and cstdio(scanf,puts,etc.)  </p>
  
  <p>P.S.: I declare the variables globally, because I will process them on a different function out of the main() function.  I set the size of the "height" of the array to (3*(r+c)-6), not to the normal (r) is because I will use the same array to store another strings later.</p>