The feof function tests for end-of-file on a stream.
It returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file.
Return value:
It returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file.
Example
import standard.C.io
import standard.C.string
define FILENAME "test.txt"
class Main {
function Main() {
var fd;
var count;
var total;
var buffer = "";
// Open file for read
if (fd = fopen(FILENAME, "r")) {
// Cycle until end of file reached
while(!feof(fd)) {
// Attempt to read in 10 bytes:
count = fread(buffer, 1, 10, fd);
// Total up actual bytes read
total += count;
echo buffer;
}
echo "Number of bytes read $total\n";
} else
echo "Problem opening the file\n";
}
}
Results
This is the file 'test.txt'.
Second line.
Number of bytes read 42