io cambierei anche il while come segue:

codice:
while (i < N && !feof(f)) {
...
}