help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fgets differ in C and octave?


From: Andreas Weber
Subject: Re: fgets differ in C and octave?
Date: Fri, 22 Feb 2019 17:32:30 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

Am 22.02.19 um 17:23 schrieb Andreas Weber:
Am 22.02.19 um 14:26 schrieb uwedamm:
If the last line was read, fgets only reports "-1", even if new data is
written to the file by the other process.

I believe what you see, is that fgets geturns -1 as soon as there is no more data to read. If you've encountered this condition, you have to clear the error state with "fclear(fid)"

A more complete example:

Open a shell and run
ping 8.8.8.8 > foo.bar

then in GNU Octave:

fid = fopen ("foo.bar", "r");
if (fid < 0)
  error ("no foo.bar found...")

else

  while (1)

    f = fgetl (fid)

    if (f < 0)
      pause (0.2);
      fclear (fid)
    endif

  endwhile

  fclose (fid)

endif

HTH, Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]