C++, reading a serial output text file backwards
<p>I'm using a serial terminal (hyperterminal) to read inputs that are continuously written from a microcontroller and dumped to a text file. I'm trying to make a C++ program that will read the integers from the text file into declared variables. The numbers that I'm interested in are at the bottom of the text file so I have to read it backwards. Also, when this function is called, it can be anywhere in the process of writing to the text file. For example, the last three lines of the text file could be something like:</p>

<p>987 1002 856 751 454 875</p>

<p>1024 1000 987 998 945 667</p>

<p>465 454 15</p>

<p>And from there I'd want to assign each number in the second last line to its own variable.</p>

<p>Some approaches I've been thinking of are:</p>

<p>Using fseek to point to the end, however I wouldn't know what offset to use because of the randomness of the last line.</p>

<p>Read in a block of three lines, identify the middle line by its line break "\n" and read 6 values from there. (Not sure how I would go about doing this, create a buffer and put it into a string? Can I do that from the bottom up?) I could even put an identifier character, like an "A" or something, at the end of each line, if that helps to search through it.</p>

<p>Any help is appreciated!</p>

<p>Thanks for the help, here's how we ended up doing it, we went backwards and used flags to bound relevant data (100 and 200, but they could have been anything) because the buffer was kinda overkill for the 6 values we needed to grab:</p>
