| Concept Framework 2.2 documentation | Contents | Index |
| Name | Version | Deprecated |
| fgets | version 1.0 | no |
| string fgets(string buffer, number n, number fd) |
| buffer | [in] Storage location for data |
| n | [in] Maximum number of characters to read |
| fd | [in] A valid file descriptor |
|
The fgets function reads a string from the input fd argument and stores it in buffer. fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n - 1, whichever comes first. The result stored in buffer is appended with a null character. The newline character, if read, is included in the string.
|
import standard.C.io
define FILENAME "test.txt"
class Main {
function Main() {
var fd;
var buffer = "";
// Open file for read
if (fd = fopen(FILENAME, "r")) {
// Read a line from stream
if (!fgets(buffer, 100, fd))
echo "fgets error\n";
else
echo buffer;
fclose(fd);
} else
echo "Problem opening the file\n";
}
}
Input test.txt
Line one.
Line two.
Results
Line one.
|
| Documented by Simona Plesuvu, generation time: Sun Jan 27 18:15:16 2013 GMT | (c)2013 Devronium Applications |