Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!topaz!root From: root@topaz.RUTGERS.EDU (Charles Hedrick) Newsgroups: net.lang.c,net.lang.pascal Subject: Interactive I/O in Pascal Message-ID: <5458@topaz.RUTGERS.EDU> Date: Tue, 29-Jul-86 20:06:06 EDT Article-I.D.: topaz.5458 Posted: Tue Jul 29 20:06:06 1986 Date-Received: Wed, 30-Jul-86 01:00:47 EDT References: <2222@brl-smoke.ARPA> <7014@boring.mcvax.UUCP> <3130@utcsri.UUCP> <175@curly.ucla-cs.ARPA> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 57 Xref: mnetor net.lang.c:5491 net.lang.pascal:350 You are right that I have heard the complaint about interactive I/O a number of times in the past. However it has appeared much less often recently, since the various implementations seem to be converging on the use of "lazy I/O". Most implementors seem to believe that the ISO standard implies that this is the correct way to handle interactive I/O. You complain that the following program will print an extra prompt. writeln ('enter an integer : '); while not eof do begin readln (i); writeln ('enter an integer : '); end; As I see it, you will have roughly the following dialog: enter an integer: 123 enter an integer: ^D at which point the program is finished. I don't see what is wrong with that. Perhaps you want enter an integer: 123^D If you want to be able to recognize that, you will simply have to use a separate call to readln. Presuming that you want to be able to recognize ^D in either context, the program would look like while true do begin writeln ('enter an integer : '); if eof then {exitloop} goto 666; read (i); if eof then {exitloop} goto 666; readln; end; 666: This tests for eof twice because I assume you want to allow it either place. (Sorry about the goto's, but the logic is clearer that way than with any alternative I could think of.) As far as I know, the semantics of lazy I/O allow you to check for any possible input, printing prompts at any point. This does not mean that Pascal's input parsing is as powerful as scanf, or that its output is as powerful as printf. Obviously they are not. Validating input, to make sure that the user hasn't typed something bogus, can require a bit more programming in Pascal than in C. For example, in the above programs, if the user types an extra CR before the ^D the program may think that there is one more number than there is. If you want the program to be very careful about checking validity of its input, you will need to write code to check that the user has typed one and exactly one number on each line. But as far as I know, you can always find a way to avoid having extra prompts and misplaced input hangs.