help-octave
[Top][All Lists]
Advanced

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

Re: End of File test is stopping on empty lines


From: Michael Goffioul
Subject: Re: End of File test is stopping on empty lines
Date: Mon, 9 Jul 2012 09:00:17 +0100



On Mon, Jul 9, 2012 at 4:01 AM, Peter Newman <address@hidden> wrote:
I  simplified the code to show the essence of the problem.
Here is the code that should skip an empty line...

1;
fid=fopen("emptyline.txt");
l = fgetl (fid);
while (l~=(-1))   
    if ~isempty(l)
            printf("%s\n", l);
   endif
l = fgetl (fid);
end

Here is the file contents of "emptyline.txt"
0010
0020

0030
0040

Why does the while loop exit on an empty line?

See the result of:

'' ~= -1
'abcde' ~= -1

and you'll understand why your loop stops at the first empty line (your loop test does a element-wise vector comparison; with an empty string, the result is an empty matrix ([]) and this is equivalent to false).

Michael.


reply via email to

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