home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol019 / reverse.pas < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  2KB  |  71 lines

  1.  
  2. (***********************************************************
  3. *
  4. *    Donated by Ray Penley, June 1980
  5. *
  6. ***********************************************************)
  7.  
  8.  
  9. PROGRAM REVERSE;
  10. {----------------------------------------------}
  11. {  Modified for Pascal/Z by Raymond E. Penley  }
  12. {----------------------------------------------}
  13.  
  14. TYPE
  15.   Links = ^Nodes;
  16.  
  17.   Nodes = record
  18.         Character  :CHAR;
  19.         Next       :Links
  20.       end;
  21.  
  22. VAR
  23.   First, This   :Links;
  24.   ix        :Integer;
  25.   Ch        :CHAR;
  26.  
  27. Procedure READ_LIST;
  28. CONST    prompt = '>>';
  29. begin
  30.   First := NIL;            { Make the list of characters empty }
  31.   Writeln;
  32.   Write(prompt);
  33.   READ(Ch);
  34.   While Ch <> '.' Do
  35.     begin
  36.     NEW(This);            { Allocate a new space }
  37.     This^.Character := Ch;    { Insert Ch at the front of the list }
  38.     This^.Next := First;    { link into the list }
  39.     First := This;
  40.     READ(Ch);
  41.     end{while}
  42. end{of Read_List};
  43.  
  44. Procedure SHOW_LIST;
  45.   (* Write all characters in the list *)
  46. VAR    count : integer;
  47. begin
  48.   Writeln;
  49.   count := 0;
  50.   This := First;
  51.   While This <> NIL DO
  52.     With This^ do begin
  53.       Write(Character);
  54.       count := count + 1;
  55.       This := Next        { Advance down the chain }
  56.     end;
  57.   Writeln;
  58.   Writeln('You entered ',count:3,' characters.');
  59. end{of Show_list};
  60.  
  61. begin
  62.   for ix:=1 to 24 do writeln;
  63.   Writeln('Enter a line of characters after the prompt.');
  64.   Writeln('Enter a "." at the end.');
  65.   While true do {infinite loop}
  66.     begin
  67.     READ_LIST;
  68.     SHOW_LIST;
  69.     end{while}
  70. end.
  71.