title: Input two matrices which didn't specialize size
body: <p>I need to input two matrices with their sizes unfixed, using a blank row to declare the end of inputting each matrix.</p>
  
  <p>For example, input:</p>
  
  <pre><code>1 2
  3 4
  (blank row here, end of input matrix 1)
  5 6 7
  8 9 10
  (blank row here, end of input matrix 2)
  </code></pre>
  
  <p>will get a 2*2 matrix and a 2*3 matrix.</p>
  
  <p>My current idea is to build a matrix large enough (like 1000*1000), then set loops and use <code>cin</code> to input each element (the code only shows how I input matrix 1):</p>
  
  <pre><code>int matx1[1000][1000];
  for (i = 0;i &lt; 1000;i++)
      {
          for (j = 0;j &lt; 1000;j++)
          {
              temp = getchar();
              if (temp == '\n')
              {
                  mat1.col = j;
                  break;
              }
              else
              {
                  putchar(temp);
              }
              cin&gt;&gt;matx1[i][j];
          }
          temp = getchar();
          if (temp == '\n')
          {
              mat1.row = i;
              break;
          }
          else
          {
              putchar(temp);
          }
      }
  </code></pre>
  
  <p>When I running this on Xcode, error happens, the <code>putchar()</code> function will interrupt my input in terminal by printing a number each time I press <code>Enter</code>, and the input result is in chaos.</p>
  
  <p>I also tried the following code to avoid use of <code>putchar()</code>:</p>
  
  <pre><code>for (i = 0; i &lt; 1000; i++)
      {
          temp = getchar();
          if (temp == '\n')
          {
              break;
          }
          else
          {
              matx1[i][0] = temp;
          for (j = 1; j &lt; 1000; j++)
          {
              cin &gt;&gt; matx1[i][j];
              if (getchar() == '\n')
              {
                  break;
              }
          }
          }
      }
  </code></pre>
  
  <p>Still, there are serious problems. The <code>temp</code> variable stores <code>char</code> and even if I convert it to <code>int</code> using ASCII, it works only if the first element of each line is smaller than 10, or the data of the first element of each line will be incorrectly stored.</p>
  
  <p>So, the main question is:</p>
  
  <p>How to switch to a new line to input the same matrix after press <code>Enter</code> once and switch to inputting the next matrix after press <code>Enter</code> again? </p>
  
  <p>Or to say: how to get the event of <code>'\n'</code> without interfering with the original input stream? </p>