title: C: Dynamically allocate a table
body: <p>I'm developing a small code that reads numbers from a file and stores them in an table. The file tells the user in the beginning the number of rows of the table (number of columns is fixed: 3)<br/>
  E.g. of file:<br/>
  <strong>3<br/>
  1  2 20.5<br/>
  1  4  9.22<br/>
  2  6  11.7<br/>
  1  3  12.1</strong></p>
  <p>As the title says, I need to allocate the table according to the number of rows that appear on my file. Can anyone give me a hand?<br/>
  So far I did this:<br/>
  Allocation<br/></p>
  <pre><code>int** table = malloc(r * sizeof(int)); //r = num of rows
      for (i = 0; i &lt; r; i++)
          table[i] = malloc(sizeof(int*) * 3); //3 is the number of columns 
  </code></pre>
  <p>Filling</p>
  <pre><code>while (fscanf(fp, &quot;%d %d %lf&quot;, &amp;a, &amp;b, &amp;c) == 3) {
      for (i = 0; i &lt; r; i++) {
      -&gt;  table[i][0]=a;
      -&gt;  table[i][1]=b;
      -&gt;  table[i][2]=c;
      }
  }
  </code></pre>
  <p>But in the lines I pointed out with &quot;-&gt;&quot; I'm getting an error saying: expression must have pointer-to-object type.</p>