Anonymous user
Read a specific line from a file: Difference between revisions
Read a specific line from a file (view source)
Revision as of 04:12, 26 November 2012
, 11 years ago→{{header|REXX}}: changed some comments, added whitespace. -- ~~~~
(Added BBC BASIC) |
m (→{{header|REXX}}: changed some comments, added whitespace. -- ~~~~) |
||
Line 681:
=={{header|REXX}}==
<lang REXX>/*REXX program to read a specific line from a file. */
parse arg fileId n . /*get the user args: fileid n */
if fileID=='' then fileId='JUNK.TXT'
if n=='' then n=7
L=lines(fileid) /*first, see if the file exists. */
if L ==0 then do; say 'error, fileID not found:' fileId; exit; end
▲if n\==1 then call linein fileId,n-1 /*second, read previous rec. to N*/
L=lines(fileid) /* L = # lines left in the file.*/
q=linein(fileId,n) /*read the Nth line, store in Q.*/
qL=length(q) /*get the length of the record. */
when L==1 & qL==0
otherwise
end /*select*/
exit /*stick a fork in it, we're done.*/
/*┌────────────────────────────────────────────────────────────────────┐
│ ─── Normally, we could just use: ─── │
|