1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>FEOF End Of File Function
</TITLE>
</HEAD>
<BODY>
<H2>FEOF End Of File Function
</H2>
<P>
Section: <A HREF=sec_io.html> Input/Ouput Functions </A>
<H3>Usage</H3>
Check to see if we are at the end of the file. The usage is
<PRE>
b = feof(handle)
</PRE>
<P>
The <code>handle</code> argument must be a valid and active file handle. The
return is true (logical 1) if the current position is at the end of
the file, and false (logical 0) otherwise. Note that simply reading
to the end of a file will not cause <code>feof</code> to return <code>true</code>.
You must read past the end of the file (which will cause an error
anyway). See the example for more details.
<H3>Example</H3>
Here, we read to the end of the file to demonstrate how <code>feof</code> works.
At first pass, we force a read of the contents of the file by specifying
<code>inf</code> for the dimension of the array to read. We then test the
end of file, and somewhat counter-intuitively, the answer is <code>false</code>.
We then attempt to read past the end of the file, which causes an
error. An <code>feof</code> test now returns the expected value of <code>true</code>.
<PRE>
--> fp = fopen('test.dat','rb');
--> x = fread(fp,[512,inf],'float');
--> feof(fp)
ans =
1
--> x = fread(fp,[1,1],'float');
--> feof(fp)
ans =
1
</PRE>
<P>
</BODY>
</HTML>
|