Read a specific line from a file: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(Changed program to use a procedure which returns the line.)
Line 1,249: Line 1,249:
=={{header|Nim}}==
=={{header|Nim}}==


<lang nim>var
<lang nim>import strformat
line: TaintedString
f = open("test.txt", fmRead)


proc readLine(f: File; num: Positive): string =
for x in 0 .. 6:
for n in 1..num:
try:
try:
line = readLine f
result = f.readLine()
except EIO:
except EOFError:
echo "Not 7 lines in file"</lang>
raise newException(IOError, &"Not enough lines in file; expected {num}, found {n - 1}.")

let f = open("test.txt", fmRead)
echo f.readLine(7)
f.close()
</lang>


=={{header|OCaml}}==
=={{header|OCaml}}==