Re: Reading to end-of-file (fgetl.m)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Reading to end-of-file (fgetl.m)

Eyal Doron
Hi,
  Kim, thanks for your file! However, the function crashes when trying
to read an empty line. You can fix this by adding "linestr=[];" before
the while loop.

Eyal Doron

Reply | Threaded
Open this post in threaded view
|

Re: Reading to end-of-file (fgetl.m)

John W. Eaton-6
Eyal Doron <[hidden email]> wrote:

:   Kim, thanks for your file! However, the function crashes when trying
: to read an empty line. You can fix this by adding "linestr=[];" before
: the while loop.

I didn't see the file fgetl.m, but the functions fgetl and fgets will
both be available as built-in functions in the next release.  Then you
can write something like

  while (isstr (s = fgetl ("file")))
    printf ("%s\n", s);
  end

to read all the lines from a file.  No error message will be printed
when the end of the file is reached.

You will also be able to limit the number of characters that are read
by adding a second parameter to fgetl/fgets.  For example,

  while (isstr (s = fgetl ("file", 10)))
    printf ("%s\n", s);
  end

reads the password file in chunks of at most 10 characters.

And no, I don't have a date set for 1.2, but I'm working on it.  Also,
I don't plan to make a 1.1.2 release because it would take too much
time away from working on 1.2.

Thanks,

jwe