title: Infinite loop when using fscanf
body: <p>I wrote this simple program in C, because I'm studying FILES right now at University. I take a txt file with a list of the results of the last race so my program will show the data formatted as I want. Here's my code:</p>
  <pre><code>/* Esercizio file Motogp */
  #include &lt;stdio.h&gt;
  #define SIZE 20
  
  int main ()
  {
      int pos, punt, num;
      float kmh;
      char nome[SIZE+1], cognome[SIZE+1], moto[SIZE+1];
      char naz[SIZE+1], nome_file[SIZE+1];
  
      FILE *fp;
  
      printf (&quot;Inserisci il nome del file da aprire: &quot;);
      gets (nome_file);
  
      fp = fopen (nome_file, &quot;r&quot;);
  
      if (fopen == NULL)
          printf (&quot;Errore nell' apertura del file %s\n&quot;, nome_file);
      else {
  
          while (fscanf (fp, &quot;%d %d %d %s %s %s %s %.2f&quot;,
                  &amp;pos, &amp;punt, &amp;num, nome, cognome, naz, moto, &amp;kmh) != EOF ) {
  
                printf (&quot;Posizione di arrivo: %d\n&quot;, pos);
                printf (&quot;Punteggio: %d\n&quot;, punt);
                printf (&quot;Numero pilota: %d\n&quot;, num);
                printf (&quot;Nome pilota: %s\n&quot;, nome);
                printf (&quot;Cognome pilota: %s\n&quot;, cognome);
                printf (&quot;Nazione: %s\n&quot;, naz);
                printf (&quot;Moto: %s\n&quot;, moto);
                printf (&quot;Media Kmh: %d\n\n&quot;, kmh);
          }
      }
  
      fclose(fp);
  
      return 0;
  }
  </code></pre>
  <p>and there's my txt file:</p>
  <pre><code>1   25  99  Jorge LORENZO    SPA    Yamaha  164.4   
  2   20  26  Dani PEDROSA     SPA    Honda   164.1   
  3   16  4   Andrea DOVIZIOSO ITA    Yamaha  163.8   
  4   13  1   Casey STONER     AUS    Honda   163.8   
  5   11  35  Cal CRUTCHLOW    GBR    Yamaha  163.6   
  6   10  19  Alvaro BAUTISTA  SPA    Honda   163.5   
  7   9   46  Valentino ROSSI  ITA    Ducati  163.3   
  8   8   6   Stefan BRADL     GER    Honda   162.9   
  9   7   69  Nicky HAYDEN     USA    Ducati  162.5   
  10  6   11  Ben SPIES    USA    Yamaha  162.3   
  11  5   8   Hector BARBERA   SPA    Ducati  162.1   
  12  4   17  Karel ABRAHAM    CZE    Ducati  160.9   
  13  3   41  Aleix ESPARGARO  SPA    ART 160.2   
  14  2   51  Michele PIRRO    ITA    FTR 160.1   
  15  1   14  Randy DE PUNIET  FRA    ART 160.0   
  16  0   77  James ELLISON    GBR    ART 159.9   
  17  0   54  Mattia PASINI    ITA    ART 159.4   
  18  0   68  Yonny HERNANDEZ  COL    BQR 159.4   
  19  0   9   Danilo PETRUCCI  ITA    Ioda    158.2   
  20  0   22  Ivan SILVA   SPA    BQR 158.2
  </code></pre>
  <p>When I run my program, it return me an infinite loop of the first one. Why?
  Is there another function to read those data?</p>