jan olieslagers said:
(e-mail address removed) schreef:
I was going to say this will read my whole datafile on every execution
(it is a once per second loop) but then I realised that the "tail"
command is very likely to do exactly the same thing...
So even this seems like a good approach, I'm afraid it's a bit over my
head (I consider myself an early beginner in C) si will first see what
popen can do for me - it's a command I hadn't even heard of.
(The "tail" command, with no additional options, prints the last 10
lines of its input.)
Actually, it's fairly likely that the "tail" command *won't* read the
entire data file. It's likely to use implementation-specific tricks.
For that matter, you can *almost* do the same thing without using any
implementation-specific tricks: use fseek() to jump to a point not far
from the end of the file, then read from there. If some of the last
10 lines are particularly long, try again from an earlier point. The
only problem is that the standard doesn't guarantee that you can do
this; the offset argument to fseek must be either 0 or a value
returned by a previous call to ftell. If absolute 100% portability
isn't an issue, you can do the same thing yourself -- or you can let
the "tail" command do that work for you.
Since both the "tail" command and the "popen" function are defined by
POSIX, not by the C standard, comp.unix.programmer would be a better
place to ask about them.