I noticed that the essential difference between the FPC
Read()
and ReadLn
functions when used with standard input
is not very well documented (in the Delphi documentation it can be read). Therefore, the answer to your question is the following.
According to the FPC
documentation, CRLF
, CR
and LF
, all are recognized as End-Of-Line (EOL)
characters, so in the following EOL
stands for any of those.
When calling Read(s)
where s: string;
the program waits for user input until an EOL
is added to the input buffer. The input characters up until (but excluding) the EOL
are removed from the buffer and passed to s
. The EOL
is left in the input buffer.
Next call to Read(s)
will immediately recognize the EOL
in the input buffer, and will not wait for user input. The EOL
continues to remain in the buffer, and therefore no subsequent Read(s)
will wait for user input.
The first call to ReadLn(s)
after a Read(s)
will also immediately detect the EOL
in the buffer and not wait for user input.
When calling ReadLn(s)
the program waits (as in previous example) for user input until an EOL
is added to the input buffer. The input characters up until (but excluding) the EOL
are removed from the buffer and passed to s
. Then the EOL
is removed from the buffer and thrown away.
Next call to ReadLn(s)
will again stop and wait for user input.
In your code you are calling Read(n)
in the very beginning of the execution. Then, in beiras()
you are calling ReadLn()
which detects the EOL
in the buffer and therefore returns immediately, but also removes the EOL
from the buffer. Subsequent calls to ReadLn()
will now wait for user input.
The cure is iow to change the Read()n
to a ReadLn(n)
in the beginning of your program.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…