title: Matrix Input from file separated by comma in C into 2D
body: <p>I'm currently taking matrix input from file into a 2D array. Given like,</p>
  
  <ul>
  <li><p>2,3,4</p>
  
  <p>1,2,3</p>
  
  <p>4,5,6</p></li>
  <li><p>3,5,6,3,1</p>
  
  <p>2,3,6,7,8</p>
  
  <p>8,7,6,5,4</p>
  
  <p>3,4,6,7,8</p></li>
  </ul>
  
  <p>The size of the matrix can vary. I'm able to do this for a 3*3 matrix with my code(given below). What change should I make so that I can input matrix of any size, like 7*7 or 5*5 ?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define MAXB 32
  #define MAXL 18
  #define MAXD 3
  
  int main(void)
  {
  int i = 0,temp,n,m,j=0;
  int numlines = 0;
  char buf[MAXB] = {0},c;
  char lines[MAXL][MAXD];
  
  FILE *fp = fopen("num.txt", "r");
  
  if (fp == 0)
  {
     fprintf(stderr, "failed to open inputs/control.txt\n");
     return 1;
  }
  
  while (i &lt; MAXL &amp;&amp; fgets (buf, MAXB - 1, fp))
  {
      if (sscanf (buf, "%hhd, %hhd, %hhd", &amp;lines[i][0], &amp;lines[i][1], &amp;lines[i][2]) == 3)
  
          i++;
  }
  
  fclose(fp);
  
  numlines = i;
  
  for (i = 0; i &lt; numlines; i++)
      for (j = 0; j &lt; MAXD; j++)
          printf (" line[%2d][%2d] : %hhd\n", i, j, lines[i][j]);
  
  printf ("\n");
  
  return 0;
  }
  </code></pre>