TIP: Click on subject to list as thread! ANSI
echo: z3_pascal
to: Keith Bolland
from: Bob Lawrence
date: 1996-06-14 08:25:38
subject: Aaargh!

KB> The problem here is that SEEK won't work on text file, so I use
 KB> untyped files. And READ and READLN won't work on untyped files,
 KB> so I need to use text files... 

  he, he, he. Frustrating, isn't it?

 KB> a) a SEEK-equivalent for text files or b) a READLN-equivalent
 KB> for untyped files?

  Stay with untyped files, BlockRead() into a buffer, and then write
your own function for reading lines character-by-character out of the
buffer until you find cr (#13). You can do it character-by-character
straight out of the file but it's too slow.

procedure ReadLnF(var F: file; var s: string);
var
   buf:        array[0..255] of char;
   n, sze:     byte;
   pos:        LongInt;
begin
   pos := FilePos(F);
   BlockRead(F, buf, SizeOf(buf), sze);
   n := 0; s := '';
   while (buf[n]  #13) and (n <= 254) do begin
      s := s + buf[n];
      inc(n);
   end;
   inc(n);
   if buf[n] = #10 then inc(n);
   Seek(F, pos + n);
end;

  That orta work. It reads a 256-byte buffer from the file, reads the
line into the string, checks for a cr or crlf, and resets the file 
pointer to the end, ready for the next line.

  It would be faster to use pointers to create the string, rather than
s := s + buf[n].

Regards,
Bob

___ Blue Wave/QWK v2.12
@EOT:

---
* Origin: Precision Nonsense, Sydney (3:711/934.12)
SEEN-BY: 633/267 270
@PATH: 711/934 808 50/99 635/544 727 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.