Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!ucbvax!decwrl!elroy.jpl.nasa.gov!csun!csuna!abcscnuk From: abcscnuk@csuna.csun.edu (Naoto Kimura) Newsgroups: comp.lang.pascal Subject: Re: file windows (was Re: Standard Pascal) Message-ID: <2100@csuna.csun.edu> Date: 28 Jul 89 17:11:48 GMT References: <8616@pyr.gatech.EDU> <18965@paris.ics.uci.edu> <4623@freja.diku.dk> <2929@virginia.acc.virginia.edu> Reply-To: abcscnuk@csuna.csun.edu (Naoto Kimura) Organization: CSU Northridge Lines: 52 In article <2929@virginia.acc.virginia.edu> scl@virginia.acc.Virginia.EDU (Steve Losen) writes: > ... (text deleted) ... >while not eof do begin > if (input^ >= '0') and (input^ <= '9') then begin > read(number); > process(number); > end > else > get(input); >end You shouldn't inspect the file buffer before checking for eof. It is an error to access the file buffer if you are at the end of file. procedure SkipJunk( ver f : text; Legal : set of char ); var done : boolean; begin if not eof(f) then repeat if f^ in Legal then done := true else begin get(f); done := eof(f) end until done end; Also, you can't inspect the file buffer to see if you're at the end of a line. According to standard, you'll end up seeing a space. The end of line marker is just that - a marker and not necessarily a character. Interactive I/O in pascal is a pain in the neck because pascal wasn't designed to be interactive. On some implementations, I've encountered problems if too many calls were made to eof or eoln when doing interactive I/O (it would lose characters). I've had to do silly things like force flushing of the buffer by outputting enough null characters to fill the output buffer in some compilers. >I admit that for most programming languages it is possible to come up >with simple and elegant solutions to selected bizarre problems. Too >bad there isn't one language that is universally applicable. >-- >Steve Losen scl@virginia.edu >University of Virginia Academic Computing Center //-n-\\ Naoto Kimura _____---=======---_____ (abcscnuk@csuna.csun.edu) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!