Read a specific line from a file: Difference between revisions

Content added Content deleted
(Changed program to use a procedure which returns the line.)
(Added 11l)
Line 8: Line 8:
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (for potential future use within the program if the code were to become embedded). If the file does not contain seven lines, or the seventh line is empty, or too big to be retrieved, output an appropriate message. If no special semantics are available for obtaining the required line, it is permissible to read line by line. Note that empty lines are considered and should still be counted. Note that for functional languages or languages without variables or storage, it is permissible to output the extracted data to standard output.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (for potential future use within the program if the code were to become embedded). If the file does not contain seven lines, or the seventh line is empty, or too big to be retrieved, output an appropriate message. If no special semantics are available for obtaining the required line, it is permissible to read line by line. Note that empty lines are considered and should still be counted. Note that for functional languages or languages without variables or storage, it is permissible to output the extracted data to standard output.
<br><br>
<br><br>

=={{header|11l}}==
<lang 11l>V f = File(‘input.txt’)
V line = 3

L 0 .< line - 1
f.read_line()
print(f.read_line())</lang>


=={{header|Ada}}==
=={{header|Ada}}==