standard.C.io.fgets

fgets is available since version 1.0.

Prototype:

string fgets(string buffer, number n, number fd)

Parameters

buffer
[in] Storage location for data
n
[in] Maximum number of characters to read
fd
[in] A valid file descriptor

Description:

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.

Return value:

fgets returns the string read.

Example
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.