Reads a line from a filechar *sm_fio_gets(int file_stream, int maxlen);
- A handle to the required file stream, obtained by sm_fio_open.
- The number of bytes to read.
maxlenbytes from the current line in
file_streamor to the end of the line and returns that string. If the current line is shorter than
sm_fio_getsonly reads up to the end of the line. If the current line is longer than
maxlen, the function returns only
maxlencharacters and sets the error code to
SMFIO_LINE_BREAK. The next read operation on this file stream by
sm_fio_getscontinues where the last read ended. This function strips newline characters before reading it into the return value.
If the read operation fails, the function returns an empty string and sets the appropriate error code. You can get this error code by calling sm_fio_error. Because an empty string can also be a valid return value—for example, the file stream contains a blank line—you should interleave calls to
sm_fio_getswith calls to
sm_fio_errorto determine whether an error condition exists and to ascertain its nature.
sm_fio_getscan set one of these error codes:
Invalid file handle.
Handle points to closed file.
Already at end of file.
Standard I/O error. Check the value in system variable
errnoto determine the nature of the error.
The line is longer than
Note: Because the same error code variable is shared by all JPL file I/O routines, you should call
sm_fio_errorbefore calling any other I/O library functions.
/* Write the contents of an ASCII file to a single- *
* line text array. The file stream handle was *
* obtained earlier by a call to sm_fio_open() *
vars str, occurNo, err, fileStream, maxOccurs
/* get array size */
maxOccurs = @widget("comments")->max_occurrences
/* get file stream handle sent from previous dialog */
receive BUNDLE f_handle DATA fileStream
/* loop through array occurrences */
for occurNo = 1 && err = 0 \
while (err == 0 && occurNo <= maxOccurs)
/* get the next string in file stream */
str = sm_fio_gets(fileStream, 32)
/* check for error condition like EOF */
if (str == "")
err = sm_fio_error()
/* read string into occurrence */
comments[occurNo] = str
/* close the file stream when done */