Read a specific line from a file: Difference between revisions

read specific line from file into Matlab or Octave
(→‎{{header|Python}}: Added PureBasic)
(read specific line from file into Matlab or Octave)
Line 412:
 
print line7$</lang>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<lang Matlab>
eln = 7; % extract line number 7
line = '';
fid = fopen('foobar.txt','r');
if (fid < 0)
printf('Error:could not open file\n')
else
n = 0;
while ~feof(fid),
n = n + 1;
if (n ~= eln),
fgetl(fid);
else
line = fgetl(fid);
end
end;
fclose(fid);
end;
printf('line %i: %s\n',eln,line);
</lang>
 
=={{header|OCaml}}==
Anonymous user