Non ho solo aggiunto una lettura.
Prima:
codice:
while (!feof (f))
{
fscanf (f, "%d", &a);
printf ("%d\n", a);
}
Dopo:
codice:
fscanf (f, "%d", &a);
while (!feof (f))
{
printf ("%d\n", a);
fscanf (f, "%d", &a);
}
Nel reference dice:
int feof ( FILE * stream );
<cstdio>
Check End-of-File indicator
Checks whether the End-of-File indicator associated with stream is set, returning a value different from zero if it is.
This indicator is generally set by a previous operation on the stream that reached the End-of-File.
[...]
Quindi la feof controlla se il flag di eof è settato.
Questo accade solo se viene fatta un'operazione (come la lettura) sullo stream.
In pratica io mi sono limitato a spostare il controllo, posizionandolo dopo la lettura (da file) e prima della stampa (a video).
Sono stato chiaro ?