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
|