On 03/31/2013 10:37, Bjartur Thorlacius wrote:
On 03/31/2013 01:52 PM, Charlie Kester wrote:
I'd read the file one character at a time, counting newlines, until I
reached the desired line. [..] Doing it this way avoids the need for a
buffer altogether, along with any guessing about possible line lengths.

Reading is expensive. Loop through an optimally sized buffer and
incrementally count newlines.

Why add this extra complexity when stdio is already buffering the input stream?



Reply via email to