title: fgets() printing the last line twice in C
body: <p>I was supposed to open a file from a command-line argument and print the values in it. This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main(int argc, char* argv[])
  {
    float num;
    char const* const filename=argv[1];
    FILE* file=fopen(filename,"r");
    char line[256];
    int j=0;
  
    while(fgets(line,sizeof(line),file)){
  
      for( j=0; j&lt;2; j++ )
      {
        if(j == 0)
        {
             fscanf(file, "%f", &amp;num);
             printf("%f \t", num);
        }
        else if(j == 1)
        {
            fscanf(file, "%f", &amp;num);
            printf("%f \n", num);
        }
      }
    }
    fclose(file);
  }
  </code></pre>
  
  <p>This is what I’d like to get as output:</p>
  
  <pre class="lang-html prettyprint-override"><code>1 1
  2 2
  3 3
  </code></pre>
  
  <p>This is what I’m actually getting:</p>
  
  <pre class="lang-html prettyprint-override"><code>1 1
  2 2
  3 3
  3 3
  </code></pre>
  
  <p>I don't get what's happening here.</p>