0

can anyone help me with the following program? There is no compile message, but during the runtime, an error is occured, and the message is, exited with exitcode=217. What seems to be the problem?

The text that the program reads is like this

3 2

1 2

1 3

1 2

Where 3 is n for instance, so the procedure the program must be done 3 times, so as all the nums., will be read.

Program sth;
Uses
SysUtils;
Var
m:Integer;
LowArr:Integer;
HighArr:Integer;
n,d:String;
f:Text;
TheArray,j:array of integer;
a:array of char;
c:array of string[1];
v:String[1];
i:Integer;

Procedure thenum ;
Begin
repeat
Read (f,a[i]);
Write(a[i]);
until (a[i]=' ');
End;

Procedure sth ;
begin
while not seekEoln and eof(f) do
begin
read(f,j[i]);
Write(j[i]);
end;
End;


procedure space;
begin
Read(f,c[i]);
Write(c[i]);
end;


Procedure theprogram;
begin
thenum;
space;
sth;
end;

begin
Assign(f,'textfile.txt');
Reset(f);
repeat
Read (f,n);
Write(n);
until (n=' ');

Read(f,v);
Write(v);
while not seekEoln and eof(f) do
begin
read(f,d);
Write(d);
end;
StrToIntDef(n,m);
setlength(thearray,m);
LowArr:=Low(Thearray);
HighArr:=High(TheArray);
for i:= LowArr to HighArr do
theprogram;
if eof(f) then;
Close(f);
Readln;
End.

1 Answer 1

2

You will get exitcode 217 if the file named textfile.txt does not exist in the same directory as the executable.

read(f,n);

will read the file into n, up to the end-of-line. Then it will get stuck. You nedd a readLN to read the newline.

Similarly, write(n); will write n to the console, but there will be no newline; you need writeln(n); to add a newline.

It's not clear quite exactly what your file-structure is. Spaces are hard to see. If you use readln(f,n); then n will contain the content of the line read - and if you want to detect an empty line, then you need until n='';, with no space between the quotes.

Since you don't supply seekEoLN with a parameter, it works on the keyboard, not the file. You need seekEoln(f) to find the end-of-line in the file.

Keep plugging away - you'll get there. I'd suggest you remove your seekEolns and take great care over whether you want to read an entire line (readln) or just a character (read)

1
  • Thank you very much, your help was really valuable.
    – MaryLyr.
    Jan 26, 2014 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.