The Input subroutines interpret the end of a line in a file according to the code used by the application to terminate the line when the file was created. Well-behaved applications and File I/O Output subroutines create files with a carriage return/newline (\r\n) sequence to indicate the end of a line. In this case, the File I/O Input subroutines terminate the line immediately after the newline character (\n). An example follows:
This will be on line 1\r\nThis will be on line 2
is interpreted as:
This will be on line 1\r\n
This will be on line 2
Conversely, a line termination sequence of \n\r causes the line to be broken immediately after the carriage return (\r). Because not all files are created using a line termination sequence of carriage return/newline, the File I/O Library subroutines can interpret lines that are terminated with a carriage return (\r) or a newline (\n) used individually. For example:
This is line 1\r\r\r\This is line 4
is interpreted as:
This is line 1\r
\r
\r
This is line 4
Also notice in the example that if a file ends without a final line terminator, the last line of the file is still included in the line number count. When lines are terminated with a newline character (\n), they are interpreted the same as in the example.
When an "end of file" terminator (^Z) is encountered, the file is terminated immediately, and any lines following the end of file terminator are not included in the line number count.
If there is no data to fill a field, it is assigned a reasonable default value instead. For integers and floats, the default value is 0, and for strings, the default value is the null string (""). Strings are read into a variable exactly as they appear in the input line. Integers are read according to the following model:
[whitespace] [sign] digits
Therefore, after digits are encountered, the next non-digit terminates the value. For example:
integer FileID
string FileName is "input.txt"
string Mode is "r"
integer X Y
record In is
X 10
Y 10
end record
...
call OpenFile (FileID, FileName, Mode)
call ReadNextRecord (FileID, In)
The following example shows the input file, INPUT.TXT.
1 2 3 4 5 6 7 8 9 10
The result is that the variable X is assigned the value 1, and the variable Y is assigned the value 6. No error is generated since this is reasonable behavior. Floats are read according to the following model:
[whitespace] [sign] [digits] [.digits]
[ {e|E} [sign] {digits} ]