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

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -