home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!gatech!news.ans.net!cmcl2!adm!news
- From: ISAACSON@husc3.harvard.edu (RON ISAACSON)
- Newsgroups: comp.lang.pascal
- Subject: Re: Look-a-head (input^) in TPASCAL...???
- Message-ID: <35202@adm.brl.mil>
- Date: 24 Jan 93 22:51:11 GMT
- Sender: news@adm.brl.mil
- Lines: 32
-
- => Would anyone have a look-a-head routine that does the same
- => thing as the UNIX 'pc' compiler 'input^' because the TPASCAL gives
- => me an error message when I try to use this in my souce code? Thanks
- => in advance to all that reply to this post.
-
- That "file buffer variable", as it's called, is something I missed
- sorely when I went over to Turbo Pascal. I wrote a little function
- to replace it. This thing is by no means foolproof, and there are
- probably several modifications that could be made, but in general
- for just looking one byte ahead in a file this function works fine.
-
- function filebuff(var infile : text) : char;
- var
- fp : longint;
- ch : char;
- begin
- {$I-} { turn off i/o checking, end of file, etc. }
- fp := filepos(infile); { get the current position into the open file }
- seek(infile, fp + 1); { move the pointer ahead by one }
- read(infile, ch); { grab a character, one ahead of the previous }
- seek(infile, fp); { go back to where we were before }
- {$I+} { turn i/o checking back on before exiting }
- filebuff := ch;
- end;
-
- This is the generic non-destructive non-pointer-moving file read
- routine. If you need something more elaborate, hopefully you get
- the general idea from this, and you can modify it to suit your
- needs. Good luck!
-
- - Ron Isaacson, Isaacson@Husc3.Harvard.Edu
-
-