Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
program Read_a_specific_line_from_a_file;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
System.SysUtils;
|
||||
|
||||
function ReadLine(position: Cardinal; FileName: TFileName): string;
|
||||
begin
|
||||
Result := '';
|
||||
|
||||
if not FileExists(FileName) then
|
||||
raise Exception.Create('Error: File does not exist.');
|
||||
|
||||
var F: TextFile;
|
||||
var line: string;
|
||||
AssignFile(F, FileName);
|
||||
Reset(F);
|
||||
for var _ := 1 to position do
|
||||
begin
|
||||
if Eof(F) then
|
||||
begin
|
||||
CloseFile(F);
|
||||
|
||||
raise Exception.Create(Format('Error: The file "%s" is too short. Cannot read line %d',
|
||||
[FileName, position]));
|
||||
end;
|
||||
|
||||
Readln(F, line);
|
||||
end;
|
||||
CloseFile(F);
|
||||
Result := line;
|
||||
end;
|
||||
|
||||
begin
|
||||
Writeln(ReadLine(7, 'test'));
|
||||
Readln;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue