If the lines you were reading were all the same length, then a calculation might be useful.
But in the situation when the lines are different lengths, I don't think there's an alternative to reading them one at a time until the line count is correct.