Subj : Re: long lines in a file To : Michael Preslar From : Roelof Beverdam Date : Sat Dec 17 2005 09:25 am Hello Nichael, >> MP> What would you guys suggest as the best way to handle such >> MP> situations? blockread() then parse 255 characters at a time? [cut] > Character by character would be waaaay to slow. Either this or a *properly implemented* use of BlockRead might do the trick, if you are lucky... Basically: without further knowledge your problem is NOT solvable. The code in your initial posting implies the usage of a compiler processing strings of indefinite length. Appearantly it was written for another compiler than the Turbo Pascal (or clone) you are using. > repeat > blockread(f,buf,2048); > s = copy(buf,1,255); > ansi_write_line(s); > until eof(f); Won't work this way. You read 2K of stuff and write only about an eighth of it. You "forget" even more data than your initial code would do. And embedded newlines are written to ansi_write_line(); the original code dropped the trailing newline (internal behaviour of readln()) and passes only the text of the line. To begin with, you would build a second loop around the copy() function and ansi_write_line() procedure moving all 2K of data in chuncks of a quarter K at a time to ansi_write_line(). If ansi_write_line() is the only procedure available to process your data, you're simply stuck! The problem cannot be solved whatever trick you may want to imagine. Only another compiler and/or the usage of PChar strings might solve it the easiest way. If Turbo Pascal is the compiler you have, you might investigate the ansi_write_xxx() portion of your code. Like Standard Pascal has a ReadLn() as well as a Read() function to read data into a string (and Turbo Pascal conforms to this standard), you should have (and probably have!) an ansi_write() as well as an ansi_write_line() function. Assuming this, you may modify your code to: begin assign(tf,'main.ans'); reset(tf); AtEof = eof(tf); while not AtEof do read(tf,s); AtEof = eof(tf); AtEoln = eoln(tf); ansi_write(s); if atEoln then begin if not AtEof then begin readln(tf); AtEof = eof(tf) end; ansi_write_line('') end end; close(tf) end. But beware: this assumes there is no need to hand over a full line of data to ansi_write_() or ansi_write_line() in a single call, but may split this over several calls. If the ansi_xxx routines don't accept this, there is no solution at all. Except choosing a proper compiler, of course... Cheers, Roelof Beverdam --- Dutchie V3.10.11 * Origin: The Beaver's Nest (2:280/5218) .