S
S
ShantMnac2014-12-18 22:23:32
Programming
ShantMnac, 2014-12-18 22:23:32

Why doesn't the Pascal program work?

type list=^point;
     point=record
      data: char;
      next: list;
     end;

procedure readList(var L: list);
  var c: char;
      temp: list;
  begin
    new(temp);
    read (c);
    temp^.data:=c;
    temp^.next:=nil;
    L:=temp;
    while not eoln do begin
      read(c);
      read(c);
      new (temp^.next);
      temp:=temp^.next;
      temp^.data:=c;
      temp^.next:=nil;
    end;
end;

procedure delDouble(var L: list);
  var 
temp1, temp2: list;
  begin
  temp1:=L;
  temp2:=L^.next;
  while temp2<>nil do begin
    if temp1^.data<>temp2^.data then begin
      temp2:=temp2^.next;
      temp1:=temp1^.next;
    end
    else
      temp2:=temp2^.next;
      temp1^.next:=temp2;
  end;
  while L<>nil do begin
    write(L^.data, ' ');
    L:=L^.next
  end;
end;

function numE(E: char; L: list): integer;
  var i: integer;
  begin
  if L^.next<>nil then begin
    if L^.data=E then 
      numE:=1+numE(E, L^.next)
  end;
end;

var L1, L2: list;
    j: char;

begin
  readList(L1);
  L2:=L1;
  delDouble(L1);
  read(j);
  numE(j, L2);
end.

Here is the program. The compiler stubbornly refuses to read j, when debugging it just goes through the line without any reaction. What's the magic?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2014-12-18
@gbg

Replace read with readln everywhere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question