Per verificare se sei giunto alla fine del file usa feof(fd); EOF è una macro che non c'entra.