fgetc reads a single character from the current position of a file associated with fd. The function then increments the associated file pointer (if defined) to point to the next character. If the stream is at end of file, the end-of-file indicator for the stream is set.
Return value:
fgetc returns the character read.
Example
import standard.C.io
define FILENAME "test.txt"
class Main {
function Main() {
var fd;
var ch = "";
var buffer = "";
// Open file for read
if (fd = fopen(FILENAME, "r")) {
// Read in the characters and place them in "buffer"
ch = fgetc(fd);
while (!feof(fd)) {
buffer+= ch;
ch = fgetc(fd);
}
echo "$buffer\n";
fclose(fd);
} else
echo "Problem opening the file\n";
}
}
Results
Line one.
Line two.