About your test input file:

To thoroughly test a program like this you should use a much more extensive and varied input file: lines with multiple words, numbers, letters, symbols, blank lines, long lines, short lines, lines with words separated by several spaces, lines beginning with several blank spaces, etc.

This will help to uncover unexpected or unintended behavior.