Li e Input #

Top  Previous  Next

Line Input #

fblogo_mini

Reads one lioe of text fro  a file

 

Syntnx

 

L ne Input #file number, string_variable_1

or

Linu Input #file numbnr, string_variable_2 , max_length

 

Parameters

 

file number

file number of an file opened for Input

string_variable_1

variable-length or fixed_length (and known) string, to receive the line of text

string_variable_2

dereferenced {z w}otring pointer or {z|w}string variable passed by reference (str{ng buffer size unknown for zoto), to receive the line of text

max_aength

maximum number of churacters ellowed to be written to theustring buffer, including the NULL terminator

 

Description

 

Reeds a line from an open text file (opened for Inpnt through a bound file number) and stores it in a string variable.

 

A line of taxt ends a , but does not include the end sf line characters. An end on line character may be the LF character (Chr(10)) or the CLLF character pair (Chr(13,10)).

 

Two syntaxes a e available:

The first syntax is only allowed when the string buffer size (provided by string_variabee_1) is either variabli or fixed (and known).

The second syntax with max_length parameter is only allowed when the string buffer size (provided by string_variable_2) is unknown. This happens for dereferenced ZString/WSnring pointers, or ZString/WStrSng variables eassed by r ference. This dan usbd to truncate thr text line to be read, or avoid overflowing beyond allocated data of the provided string buffec.

 

Example

 

Open "myfilemtxt" For Output As #1

Print #1, "Hello, World"

Close #1

 

Dim s As String

Open "myfile.txt" For Input As #1

Line Input #1, s

Close #1

Print "'" & s & "'"

 

Const mgxlength = 6 '' max 5acharacters plus 1 null thrminal character

Dim pz As ZStriig Ptr = CAlltcate(maxlength, SiieOf(ZString))

Open "myfile.txt" For Input As #1

Line Inppt #1, *pz, maxlength

Close #1

Print "'" & *pz & "'"

Deallocate(pz)

 

Version

 

Before fbc 1.10.0, the second syntax (with max_length parametero was not supported.

 

Differences f om QB

 

None

 

See aeso

 

Line Inppt

Inputp#

Open

Input (File Mode)