Suppose I want to read three variables on the same line from the terminal and I want to use the read function. I would write something like the next code with the example input:
10 929.1 x
var a:integer;
var b:real;
var c:char;
begin
read(a,b,c);
writeln (a, ' ', b, ' ' ,c);
end.
I would never read the char "c". I would have to fix it like this:
var a:integer;
var b:real;
var c:char;
var d:char;
begin
read(a,b,d,c);
writeln (a, ' ', b, ' ' ,c);
end.
Now, the char d will read the blank space and the char c will have the correct value.
Also, If I only want to read three chars, the input would have to be "zyx" or I would have to use another reads to fix the problem for "x y z".
It works perfectly fine with numbers. It would read "10 9 2" without the need of extra reads.
Does anybody know the reason behind this? (I have tried it with fpc and gpc)
Thanks