title: Storing decimal numbers from a text file to an array in C
body: <p>I'm trying to store 10 decimal numbers from a text file into an array. My problem is that it is skipping several numbers until it reaches the end of line.</p>
  
  <p>I debugged the program by printing out the number of cycles the program took for reaching the end of the file, and resulted 10. And it is the correct value of how many numbers there are in the file. But when I display the element values of the array, only 5 numbers are there. When I compare the stored numbers with the text file numbers, It results that several numbers are being skipped.   </p>
  
  <p>Here is my code below : </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  main(void) 
  {
     FILE *inp;         /* pointer to input file */
  
     double item;
     int cnt=0,y,d,i;
     double array[300],swap;  
  
     /* Prepare files for input */
     inp = fopen("C:/Users/infile.txt", "r");
  
  
     /* Read each item */
     while ( (fscanf(inp, "%lf", &amp;item) == 1) &amp;&amp; (!feof(inp)) ) {
       array[cnt] = item;
       cnt++; 
     }
  
  
     for (int i = 0; i &lt; cnt; i++)
     {
        printf("%lf\n",array[i]);
        i++;
     }
     printf("%d",cnt);
  
  
    fclose(inp); /* Close the files */
  
    return (0);
  }
  </code></pre>
  
  <p>-In the text file there are 10 double numbers ranging from 0 to 101 (ex 15.12563) </p>
  
  <p>-The value for the cycle times of the while loop is 10 (cnt reaches 10)</p>
  
  <p>-My code only stores 5 numbers instead of 10, which is skipping the rest 5 numbers, but it says it has reached the last value at line 10.</p>
  
  <p>These are the values in the text file: </p>
  
  <p>21.388000</p>
  
  <p>12.372628</p>
  
  <p>21.961366</p>
  
  <p>85.616285</p>
  
  <p>30.123001</p>
  
  <p>30.271053</p>
  
  <p>70.733982</p>
  
  <p>35.867327</p>
  
  <p>48.339462</p>
  
  <p>82.459009</p>
  
  <p>If I left some key information about my concern please ask. Thanks  </p>