Read a specific line from a file: Difference between revisions

m
→‎{{header|ALGOL 68}}: Small simpliofication, removed extraneous blank-lines, removed output section
(→‎{{header|PL/M}}: Added note.)
m (→‎{{header|ALGOL 68}}: Small simpliofication, removed extraneous blank-lines, removed output section)
Line 88:
, REF STRING err
)BOOL:
IF FILE input file;
BEGIN
line := "";
 
FILE open( input file;, file name, stand in channel ) /= 0
THEN
 
line := "";
err := "";
 
IF open( input file, file name, stand in channel ) /= 0
THEN
# failed to open the file #
err := "Unable to open """ + file name + """";
FALSE
ELSE
 
ELSE
# file opened OK #
err := "";
 
BOOL at eof := FALSE;
 
# set the EOF handler for the file #
on logical file end( input file
Line 118 ⟶ 111:
END
);
 
INT line number := 0;
STRING text;
 
WHILE line number < number
AND NOT at eof
DO
 
get( input file, ( text, newline ) );
line number +:= 1
 
OD;
 
# close the file #
close( input file );
 
# return the line or an error message depending on whether #
# we got a line with the required number or not #
Line 146 ⟶ 133:
FALSE
FI
END FI; # read specific line #
 
FI
 
END; # read specific line #
 
 
main:(
# read the seventh line of this source and print it #
# (or an error message if we can't) #
 
STRING line;
STRING err;
 
IF read specific line( "read-specific-line.a68", 7, line, err )
THEN
Line 167 ⟶ 147:
print( ( "unable to read line: """ + err + """" ) )
FI
 
)</lang>
{{out}}
<pre>
line seven is: " , INT number # line 7 #"
</pre>
 
=={{header|AutoHotkey}}==
3,028

edits