reading the last line from a file in nxc

131 Views Asked by At

I am trying to find a way of reading the last line in a text file in NXC and return the numerical value within the file but if the value is negative it returns the value with a 0 at the beginning instead of -. I can loop through all the lines of text until the end but this gives me the error so am hoping to rectify this problem by directly reading the last known entry. Is this possible and how?

see Negative values returned from file in NXC for the code.

1

There are 1 best solutions below

0
On

You can set file position indicator to any position in the file with fseek.

http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group__cstdio_a_p_i_gabea819317fe740c7376ca24eaf1225c6.html#gabea819317fe740c7376ca24eaf1225c6

fseek(handle, -10, SEEK_END);

I do not recommend to use this function. It's a bit tricky to get it work. Use the method used in your link.