Hi,
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'.
Cooper/Clancy write (p 15 of the cited German version of "Oh! Pascal!"
- retranslated by me, please excuse my poor English):
"Regarding the input of chars the blank is (just like the RETURN) regarded
as a char of its own, regarding numerical input the blanks are used as
dividing marks and not used otherwise. The computer treats them as if they
simply didn't exist."
So what?
Yes, I know, this is a real beginner's question, but I just don't get the
clue. It would be nice to get some hints, especially sources of
information.
Tx in advance,
Dirk Weber
Yes, I think this is a real beginner's question.


|