{ File: bufftas.pas }

{ Scopo: funzionamento del buffer di tastiera }

program BufferTastiera;
{ Illustra il funzionamento del buffer di tastiera. }

var
  c1, c2, c3, c4, c5 : char;

begin
  writeln('Ciao');      { 1 }
  readln(c1, c2, c3);   { 2 }
  writeln('Ciao2');     { 3 }
  read(c4);             { 4 }
  writeln('Ciao3');     { 5 }
  read(c5);             { 6 }
  writeln('Fine');      { 7 }
  writeln;
  writeln("c1:", ord(c1));
  writeln("c2:", ord(c2));
  writeln("c3:", ord(c3));
  writeln("c4:", ord(c4));
  writeln("c5:", ord(c5))
end. { BufferTastiera }


{ Contenuto dello schermo (# denota il carattere di a-capo):

  Istr. +------------------------------+
  1     |Ciao                          |
  2     |a#                            |
  2     |bcd#                          |
  3     |Ciao2                         |
  4     |e#                            |
  5,6   |Ciao3                         |
  7     |Fine                          |
        |                              |
        +------------------------------+

  Contenuto del buffer di tastiera al termine dell'esecuzione:
  +----------------+
  |a#bcd#e#        |
  +----------------+

  Contenuto della memoria al termine dell'esecuzione:

      |...|
      +---+
  c1  | a |
      +---+
  c2  | # |
      +---+
  c3  | b |
      +---+
  c4  | e |
      +---+
  c5  | # |
      +---+
      |...|

  N.B. In ambiente MS-DOS e WINDOWS un carattere di a-capo corrisponde in
       realta` a due caratteri (carriage-return e line-feed).
       Quindi, il comportamento del programma in ambiente MS-DOS e WINDOWS
       NON corrisponde a quanto sopra illustrato.

}