0
votes

I wrote this program and I just can't figure out what is wrong with it. The SkaitytiDuomenis (read values) procedure takes two arrays as arguments so it can read coordinates from a text file and store them in the arrays, but the problem is it doesn't really read it. There is something wrong with the assign() part, but I can't figure it out for the life of me. Anyone who helps will be greatly appreciated, as this is a state exam I'm trying to prepare for.

program Uzduotis1;
type
    masyvas = array[1..50] of integer;
{*************************Kintamieji************************}
var
    Duomenys, Rezultatai :text;
    x, y                 :masyvas;       {koordinates (x;y) }
    UzsakymuSk,                           {uzsakymu skaicius}
    DienosKm,                    {dienos kilometrazo limitas}
    NuvaziuotiKm,                 {nuvaziuotu kilometru suma}
    LikeKlientai,             {neaptarnautu klientu skaicius}
    UzsakymoNr                  {atliekamo uzsakymo numeris}
                         :integer;
{*************************Proceduros************************}
procedure SkaitytiDuomenis(var a,b:masyvas);
var i:integer;
begin
    for i:=1 to UzsakymuSk do
        readln(Duomenys, a[i], b[i]);
end;
procedure IsvestiRezultatus;
    begin
        rewrite(Rezultatai);
        write(LikeKlientai,' ',NuvaziuotiKm);
        close(Rezultatai)
    end;
{************************Funkcijos**************************}
function atstumas(a,b :integer) :integer;
    begin
        atstumas := (abs(a) + abs(b)) * 2;
    end;
{********************Pagrindine programa********************}
begin
    assign(Duomenys,'C:\Duomenys\U1.txt');
    assign(Rezultatai,'C:\Duomenys\U1rez.txt');
    reset(Duomenys);
    readln(Duomenys,UzsakymuSk,DienosKm);
    SkaitytiDuomenis(x,y);
    NuvaziuotiKm := 0;
    LikeKlientai := UzsakymuSk;
    UzsakymoNr := 1;
    while ((UzsakymoNr<UzsakymuSk) and (NuvaziuotiKm<DienosKm)) do
        begin
            NuvaziuotiKm := NuvaziuotiKm + atstumas(x[UzsakymoNr],y[UzsakymoNr]);
            LikeKlientai := LikeKlientai - 1;
            UzsakymoNr := UzsakymoNr + 1
        end;
    IsvestiRezultatus;
end.

This is the input file:

14 30
2 3
3 –1
-2 –4
–3 0
-2 4
0 2
5 -4
1 2
4 -3
2 1
-5 -5
-1 0
0 5
2 5
2
Any news on this problem? - lurker

2 Answers

0
votes

Did you copy/paste the input text file to your problem directly from your PC? When I copied it out, I found some unintended characters:

$ od -c U1.txt
0000000   1   4       3   0  \n   2       3  \n   3     342 200 223   1
0000020  \n   -   2     342 200 223   4  \n 342 200 223   3       0  \n
0000040   -   2       4  \n   0       2  \n   5       -   4  \n   1
0000060   2  \n   4       -   3  \n   2       1  \n   -   5       -   5
0000100  \n   -   1       0  \n   0       5  \n   2       5  \n

So after reading the first two lines, which works, it croaks when it tries to read two ASCII integer values from the 3rd line since it's not valid text. I removed lines 3, 4, and 5 from the original file, then the program ran.

Try regenerating your text file. Or check the program that generates it, if that's what you have.

0
votes

Your input file is not the correct format. It contains the hex UTF8 character sequence E2 80 93 which equates to the en-dash, code point 8211 decimal.

This is probably because the file was created with a word processor rather than a text editor, rarely a good idea.

Just replace the en-dash characters with genuine - ones (code point 45 decimal) and all should be well.