title: How to read a text file that has float numbers to a float array in C
body: <p>I have been trying to read a text file with the following:</p>
  
  <pre><code>0.000   1.800   3.240   4.374   5.249   5.905   6.377   7.696   6.887   6.974   6.974   6.904   6.778   6.609   6.406   6.177   5.930   5.670   5.403   5.133   4.863   4.596   4.333   5.077   3.829   4.589   3.360   3.140   2.931   2.732   2.543   2.365   2.198   2.040   1.891   1.752   1.622   1.500   1.387   1.281   1.182   1.091   2.006   0.927   0.853   0.786   0.723   0.665   0.611   0.561   0.515   0.473   0.434   0.398   0.365   0.335   0.307   0.281   0.257   0.236   0.216   1.197   0.180   0.165   0.151   0.138   0.126   0.115   0.105   0.096   0.088   0.080   0.073   0.067   0.061   1.055   0.051   0.046   0.042   0.038   0.035   0.032   0.029   0.026   0.024   0.022   0.020   0.018   0.017   0.015   0.014   0.012   0.011   0.010   0.009   0.009   0.008   0.007   1.006   0.006   0.005   0.005
  </code></pre>
  
  <p>This numbers are as formatted above in text file. </p>
  
  <p>My code is as follows</p>
  
  <pre><code>#include &lt;stdio.h&gt; 
  
  #include &lt;stdlib.h&gt;
  
  void main()
  
  {
  
          FILE *file = fopen("Data.txt", "r");
          float integers[102];
  
          int i=0;
          int num;
          while(fscanf(file, "%f", &amp;num) &gt;0) {
              integers[i] = num;
              i++;
          }
          if( file == NULL )
           {
              printf("Error while opening the file.\n");
  
           }
          fclose(file);
          for(i = 0;i &lt;102; i++){
          printf("integers[%d] = %f",i, integers[i]);
          }
  
  
  }
  </code></pre>
  
  <p>The output of the <code>printf</code> is that all the elements in integers are zero when ran. Also when trying to debug I notice the compiler skips the while loop. I'm using Code Composer Studios.</p>