From: Yuquan DU on
Hi, all

I want to read the content of diary file during the intervals of writing to the diary file. I decrible my needs with the pseudo-code in the following.

%==============pseudo-code starts============
diary('log.txt');
diary on;
....
write to 'log.txt'; (Indeed, the write operation is auto-done by another software)
read from 'log.txt';
....
write to 'log.txt';
read from 'log.txt';
....
diary off;
%==============pseudo-code ends============

My question is,
How can I read the diary file during the intervals of (auto-done) writing?
From: Walter Roberson on
Yuquan DU wrote:

> I want to read the content of diary file during the intervals of writing
> to the diary file. I decrible my needs with the pseudo-code in the
> following.
>
> %==============pseudo-code starts============
> diary('log.txt');
> diary on;
> ....
> write to 'log.txt'; (Indeed, the write operation is auto-done by another
> software)
> read from 'log.txt';
> ....
> write to 'log.txt';
> read from 'log.txt';
> ....
> diary off;
> %==============pseudo-code ends============
>
> My question is,
> How can I read the diary file during the intervals of (auto-done) writing?


fseek(fid, ftell(fid), 'bof')

will reset the end-of-file flag and allow you to continue reading.

Note: on Windows, ftell() only returns a byte count for binary files and
not for text files, so do not try to do character counting on text files.
From: Yuquan DU on
Thanks a lot, Walter.

But I cannot get the file identifier of the diary file unless I use the command "fopen('log.txt','r')". However, before the "diary off", I cannot use "fopen" with the option 'r'(read), since the diary file is in written mode before "diary off".

Best regards.

Yuquan DU


Walter Roberson <roberson(a)hushmail.com> wrote in message <jO1Rn.76431$HG1.47728(a)newsfe21.iad>...
> Yuquan DU wrote:
>
> > I want to read the content of diary file during the intervals of writing
> > to the diary file. I decrible my needs with the pseudo-code in the
> > following.
> >
> > %==============pseudo-code starts============
> > diary('log.txt');
> > diary on;
> > ....
> > write to 'log.txt'; (Indeed, the write operation is auto-done by another
> > software)
> > read from 'log.txt';
> > ....
> > write to 'log.txt';
> > read from 'log.txt';
> > ....
> > diary off;
> > %==============pseudo-code ends============
> >
> > My question is,
> > How can I read the diary file during the intervals of (auto-done) writing?
>
>
> fseek(fid, ftell(fid), 'bof')
>
> will reset the end-of-file flag and allow you to continue reading.
>
> Note: on Windows, ftell() only returns a byte count for binary files and
> not for text files, so do not try to do character counting on text files.