Perché l'ultimo carattere ignorato è il '\n' (il ritorno a capo), che è quello che fa la while che ti ho suggerito.