A good example how the manage the discrepancies in the Read() function in pascal

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: Source in Pascal

Author: PCRevue 4/96
Program: Readinp.pas
File exe: Readinp.exe

A good example how the manage the discrepancies in the Read() function in pascal. The program allowes to write the text up to 10 chars but not to continue on the next line.
{ POUZI.PAS                                    Author: PCRevue 4/96 }
{ Ukazkovy priklad ako opravit nedostatky funkcie Read()            }
{ Program dovoli pisat text len do 10 znakov a nedovoli prejst na   }
{ novy riadok.                                                      }
{                                                                   }
{ Datum:04.1996                                http://www.trsek.com }
 
program Read_Input;
uses crt,dos;
var st:string;
 
{ precita len retazec o maximalnej dlzke x-znakov }
{ retazec bude ulozeny v premennej s }
procedure ReadInput(var s:string;x:byte);
var reg:registers;
    pom:string;
begin
  with reg do begin
    ah:=$0a;
    ds:=seg(pom);
    dx:=ofs(pom)-1;
   end;
  mem[reg.ds:reg.dx]:=x+1;
 
  msdos(reg);
  s:=pom;
end;
 
begin
 ClrScr;
 Write('Zadaj meno:');
 ReadInput(st,10);
 
 ClrScr;
 Writeln('Tvoje meno je:',st);
 ReadLn;
end.