Reputation: 583
Im trying to convert an input like the following:
1 5 9 12 16 21 25
3 7 12 13 14 15 16 19 20 26
Into 2 arrays, one array for each line of input. Currently I have the following code:
FUNCTION readId : integer;
VAR
id : integer;
i : integer;
first : a;
second : a;
TYPE
a = ARRAY[0..(size - 1)] OF integer;
BEGIN
i := 0;
WHILE (NOT eoln) DO BEGIN
read(id);
first[i] := id;
Inc(i);
END;
i := 0;
WHILE ((NOT eof) AND (NOT eoln)) DO BEGIN
read(id);
second[i] := id;
Inc(i);
END;
END;
This works for the first array, but the second array isn't filled. What am I doing wrong?
Upvotes: 0
Views: 233
Reputation: 1438
The first while
loop will end when eoln
is true
, and at the beginning of the second while
loop eoln
is still true
. This means that the body of the second while
loop is never executed, because the condition, ((not eof)) and (not(eoln))
, will be false
.
You can try putting a readln
before the second while
loop.
Upvotes: 1