Dirk Weber wrote:
>
> I do not really understand where the mistake is: In my understanding
> of the read statement or in the book I use for self studying Pascal.
>
> Here the program listing
> ..........
>
> program selbsttest_s_25;
> uses crt;
>
> var
> z1,z2:char;
> n1,n2:integer;
>
> const
> cz1='z1';
> cz2='z2';
> cn1='n1';
> cn2='n2';
>
> BEGIN
> clrscr;
>
> writeln('Cooper/Clancy, Pascal, Braunschweig 1991, p. 25, Selbsttest');
>
> z1:=' ';
> z2:=' ';
> n1:=0;
> n2:=0;
>
> writeln('Please enter 123 a45b');
> read(n1,z1,z2,n2);
> writeln(z1:5,z2:5,n1:5,n2:5);
> writeln;
> END.
> ................
>
> My problem
>
> According to Cooper/Clancy the variables should have the following
> contents:
>
> z1: A blank
> z2: 'A'
> n1: 123
> n2: 45
>
> I cmpiled the program with fpc, option was default, i. e. FreePascal
> dialect.
>
> Running the program resulted in a runtime error.
>
> The error message was:
>
> Runtime error 106 at $08048199
> $08048199 main , line 46 of selbsttest_s_25.pas
> $0804809F
>
> :-(
>
> My system environment:
>
> OpenSuSE 10.2
>
> The program was compiled with help of the fp ide.
>
> Now, why is there a runtime error?
>
> If I understood right, what Cooper/Clancy wrote, the following should
have
> happened:
>
> n1 reads 123, the integer is ended with the blank.
> z1 reads 'A'
> z2 reads '4'
> n2 reads 5, the integer is ended with the non numeric 'B'.
This sounds as if FPC has copied the (faulty) action of TPs read
function, as I mentioned earlier. Once more, see my txtfiles
unit. I don't know if it works under FP, because it depends on the
precise format of file control blocks and error exits in TP.
Your book is correct, at least in this matter.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews


|