c - total number of lines of a file (counting backwards) -



c - total number of lines of a file (counting backwards) -

for given file, can count number of lines backwards? i.e. starting eof, counting lines till beginning?

i fseek end of file. start form there, maintain looking new line char (indication of new line) , maintain incrementing line_number count. should ending condition?

is there opposite of eof? :)

my own suggestion: if looking xth line end, origin @ line number : total_lines - x --- fair enough?

motive: interested in getting xth line form end of huge (read huge) file. so, looking optimal solution.

ps: not homework (though lifetime pupil :p)

the opposite of eof pos == 0.

the posix tail command this; illustration code, see http://www.koders.com/c/fid8dee98a42c35a1346fa89c328cc3bf94e25cf377.aspx

c file eof

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -