title: read text file contain matrix C++
body: <p>I need to simple program on C++ which can take two matrices from text file and also it take the number of row and column of each one like this:</p>
  
  <p>this is ex for which is text file contain   </p>
  
  <pre><code>3 5
  1 -2 3 4 5
  1 2 -3 4 5
  -1 2 3 4 5
  5 4
  -1 2 3 4
  1 -2 3 4
  1 2 -3 4
  1 2 3 -4
  -1 -2 -3 -4
  </code></pre>
  
  <p>the first line of each matrix contain it`s number of row and column</p>
  
  <p>and this is the prog which i tried to do it</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;cstring&gt;
  #include &lt;fstream&gt;
  #define Height 3
  #define Width  5
  // I assume that each input line in the file can contain at most width * 3 characters.
  // Three extra characters for NL, CR, 0.
  // Change this if you expect the file to contain longer lines.
  #define BUFFER_WIDTH (Width * 3 + 3)
  unsigned char Map[Height][Width];
  char line[BUFFER_WIDTH];
  // Remove CR, NL at the end of the line.
  void clean_line(char *line)
  {
   int len = strlen(line);
    while (len &gt; 0 &amp;&amp; (line[len - 1] == '\n' || line[len - 1] == '\r'))
  {
   line[len - 1] = '\0';
   len--;
    }
  }
  int main ()
  {
  FILE *fp = fopen("input1.txt","r");
  int row = 0;
  while (!feof(fp) &amp;&amp; row &lt; Height)
    {
    fgets(line, BUFFER_WIDTH, fp);
    clean_line(line);
    int len = strlen(line);
    int rowLen = len &gt; Width ? Width : len;
  for (int col = 0; col &lt; rowLen; col++)
  {
    Map[row][col] = line[col];
    printf("%d  ",Map[row][col]);
   }
  printf("\n");
  row++;
   }
  fclose(fp);
   return 0;
  }
  </code></pre>