basic.%fgets

C Function/BASIC Program, Releases: AP/Unix

Reads a C string from a stream.

Syntax

ptr=(char*)%fgets( variable, n, (char*)stream )

Description

reads characters from the named input 'stream' into 'variable' until 'n'-1 characters are read or a new line character is read and transferred to the string.
The string is then terminated with a null character (hex '00'). A string of a size at least equal to 'n' must have been assigned to 'variable' before the call, otherwise the data is truncated. If less than n-1 bytes are returned, the content of the string beyond is undefined, as is usual in C. No data translation occurs.

The 'pointer' returned has no meaning, except for a null value which indicates an error or that end of file has been encountered.

Example

char line[128] ;* make a buffer
pointer=(char*)%fgets( line, 128, (char*)stream )
if pointer#0 then
line=field(line,char(0),1)
print line
end

See Also

Command Name Type Description
basic.cfunc Definition can be called from a Pick/BASIC program or subroutine in AP/DOS and AP/Unix implementations using a syntax similar to that of normal C.
basic.cfunction Definition Declare a list of C functions.
basic.%fclose C Function Closes stream.
basic.%fgetc C Function Gets a character from a stream.
basic.%fopen C Function Opens a stream.
basic.%popen C Function Creates pipe between calling process and command.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.