title: Reading and Printing a Matrix C
body: <p>I have an assignment to read numbers from a file to form a matrix. 
  The first two integers of each line are the row and column, and then the remaining integers are the data in the matrix.</p>
  
  <pre><code>2 2 1 2 3 4
  </code></pre>
  
  <p>looks like</p>
  
  <pre><code>1 2
  3 4
  </code></pre>
  
  <p>I am able to successfully load in one matrix using:</p>
  
  <pre><code>void RdMatrix(FILE *file, int (*matrix)[MAXSIZE][MAXSIZE], int *row, int *column)
  {
      int data;
  
      int matRow = RdRowSize(file);
      int matCol = RdColumnSize(file);
      *row = matRow;
      *column = matCol;
      int i, j;
  
      for (i = 0; i &lt; matRow; i++)
      {
          for (j = 0; j &lt; matCol; j++)
          {
              fscanf(file, "%d", &amp;data);
              *matrix[i][j] = data;
          }
  }
  </code></pre>
  
  <p>Then I can print it with </p>
  
  <pre><code>void PrMat(int(*matrix)[MAXSIZE][MAXSIZE], int row, int col)
  {   
      int i, j;
      printf("\n");
      for (i = 0; i &lt; row; i++)
      {
          for (j = 0; j &lt; col; j++)
          {
              printf("%d ", *matrix[i][j]);
          }
          printf("\n");
      }
      printf("\n");
  }
  </code></pre>
  
  <p>In my main function, I have two matrices <code>A[MAXSIZE][MAXSIZE]</code> and <code>B[MAXSIZE][MAXSIZE]</code>, a <code>rowA = 0, colA = 0;</code> and <code>rowB = 0, colB = 0;</code>.
  I call <code>RdMatrix(fpin, &amp;A, &amp;rowA, &amp;columnA);  RdMatrix(fpin, &amp;B, &amp;rowB, &amp;columnB); PrMat(&amp;A, rowA, columnA);</code></p>
  
  <p>The input looks like:</p>
  
  <pre><code>2 2 1 2 3 4
  2 2 9 8 7 6
  </code></pre>
  
  <p>Then it prints </p>
  
  <pre><code>1 2 
  9 8
  
  9 8 
  7 6
  </code></pre>
  
  <p>When it should be printing</p>
  
  <pre><code>1 2
  3 4
  
  9 8
  7 6
  </code></pre>
  
  <p>I'm not allowed to use any libraries, nor will it help, since I have to re-write this in assembly later.</p>
  
  <p>EDIT: Including Code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define MAXSIZE 10
  FILE *fpin;
  
  int RdRowSize(FILE *file)
  {   
      int row;
      fscanf(file, "%d", &amp;row);
      return row;
  }
  
  int RdColumnSize(FILE *file)
  {
      int col;
      fscanf(file, "%d", &amp;col);
      return col;
  }
  
  void RdMatrix(FILE *file, int (*matrix)[MAXSIZE][MAXSIZE], int *row, int *column)
  {
      int data;
  
      int matRow = RdRowSize(file);
      int matCol = RdColumnSize(file);
      *row = matRow;
      *column = matCol;
      int i, j;
  
      printf("\n=====================\nLoading Matrix\n=====================\n");
      for (i = 0; i &lt; matRow; i++)
      {
          for (j = 0; j &lt; matCol; j++)
          {
              fscanf(file, "%d", &amp;data);
              *matrix[i][j] = data;
          }
      }
  }
  
  void PrMat(int(*matrix)[MAXSIZE][MAXSIZE], int row, int col)
  {   
      int i, j;
      printf("\n");
      for (i = 0; i &lt; row; i++)
      {
          for (j = 0; j &lt; col; j++)
          {
              printf("%d ", *matrix[i][j]);
          }
          printf("\n");
      }
      printf("\n");
  }
  
  
  int main(void) 
  {
  
      int RsizeM, CsizeM;                                 /*matrix row size and column size*/
      int A[MAXSIZE][MAXSIZE], B[MAXSIZE][MAXSIZE];       /*the two matrices*/
      int rowA=0, columnA=0, rowB=0, columnB=0;           /* the row and column sizes of A and B */
  
  
  
  
      /*open input file - file name is hardcoded*/
      fpin = fopen("INA1.txt", "r");                      /* open the file for reading */
      if (fpin == NULL) 
      {
          fprintf(stdout, "Cannot open input file  - Bye\n");
          return(-1);                                 /* if problem, exit program*/
      }
      /*ASSUMPTIONS: the file is not empty and contains has at least 1 set of matrices*/
  
  
      /* Add while loop after testing a single iteration */ 
  
  
      RdMatrix(fpin, &amp;A, &amp;rowA, &amp;columnA);
      RdMatrix(fpin, &amp;B, &amp;rowB, &amp;columnB);
  
      PrMat(&amp;A, rowA, columnA);
      PrMat(&amp;B, rowA, columnB);
  
  
  
      fclose(fpin);  /* close the file */
  
      return (0);
  }
  </code></pre>
  
  <p>Then the file it has to open is called INA1.txt</p>