Is there a way to seek to a particular location in a file?

AceAce
edited March 2018 in How To...

Hi everyone,

I'm trying to figure out an efficient way to get a comment from the end of a png image file. It's near the end of the file, so I would like to work backwards from the end instead of starting at the beginning and parsing through all the image data.

General algorithm would be: 1) open the file 2) seek to the end 3) search backwards for "%tEXt Comment " 4) read forwards for comma separated fields of numbers and text 5) somehow parse out that info. Mainly what I need is the first number, which can be 0 through 12, and convert it from ascii digits to a number.

It'd be easy for me to figure out how to do it in C, but I'm not sure how to seek to the end and then search backwards. Is that possible? I've done some online searching and have gotten to the relevant data by searching forward, but I would like to do it more efficiently than reading through everything since I'll be working with multiple images.

Any tips would be appreciated.

Answers

Sign In or Register to comment.