Don't use getting characters to check for EOF in this situation, otherwise you need to seek back (or "unget" the character, especially if you're dealing with stdin since seeking probably won't work...