Board index » delphi » Read data file; write text file

Read data file; write text file

        I'm trying to replicate my tiny Clipper app that reads a data stream file
(no CR or LFs) and writes it out to a text file with hard returns, but I've
hit a snag.
        The user needs to supply the line length, anywhere from 10 to 300 bytes.
The code below works for a fixed size "Buf", but I can't use a variable in the
array declaration, and I gave up on dynamic arrays because frankly, I don't
know what I'm doing.  ;-)
        Any help, or alternative read/write methods, would be Greatly appreciated!
    (I'm using D4.)

-----------------
var
  InFile: file;
  OutFile: TextFile;
  Buf: array[1..29] of Char;    <--------- How do I make this value variable?

begin
  AssignFile(OutFile, 'd:\output.txt');
  Rewrite(OutFile);
  AssignFile(InFile, 'd:\input.tbl');
  Reset(InFile, 1);

  while not Eof(InFile) do
  begin
    BlockRead(InFile, Buf, SizeOf(Buf));
    WriteLn(OutFile, Copy(Buf, 1, 29));    <-- this line is a problem too...
  end;
  CloseFile(InFile);
  CloseFile(OutFile);
  showmessage('done');

bn...@XXXsympatico.ca  (remove XXX to reply)  

 

Re:Read data file; write text file


Quote
On Thu, 22 Mar 2001 00:44:57 GMT, bn...@XXXsympatico.ca wrote:
>    I'm trying to replicate my tiny Clipper app that reads a data stream file
>(no CR or LFs) and writes it out to a text file with hard returns, but I've
>hit a snag.
>    The user needs to supply the line length, anywhere from 10 to 300 bytes.
>The code below works for a fixed size "Buf", but I can't use a variable in the
>array declaration, and I gave up on dynamic arrays because frankly, I don't
>know what I'm doing.  ;-)
>    Any help, or alternative read/write methods, would be Greatly appreciated!
>    (I'm using D4.)

>-----------------
>var
>  InFile: file;
>  OutFile: TextFile;
>  Buf: array[1..29] of Char;    <--------- How do I make this value variable?

Why don't you just provide the maximum line length for the buffer (if
it's a maximum of 300 bytes, that doesn't "cost" you anything
Quote

>begin
>  AssignFile(OutFile, 'd:\output.txt');
>  Rewrite(OutFile);
>  AssignFile(InFile, 'd:\input.tbl');
>  Reset(InFile, 1);

>  while not Eof(InFile) do
>  begin
>    BlockRead(InFile, Buf, SizeOf(Buf));
>    WriteLn(OutFile, Copy(Buf, 1, 29));    <-- this line is a problem too...

And then use the "variable" line length to read and write the lines,
like

BlockRead (Infile, Buf, LineLength);
WriteLn (OutFile, Copy (Buf, 1, LineLength));

Quote
>  end;
>  CloseFile(InFile);
>  CloseFile(OutFile);
>  showmessage('done');

or do i miss something (beside i don't know right out of my head if
the Copy function on the buffer works on more than 255 bytes in D4 (it
does in D5))

Ralf

Re:Read data file; write text file


        I _could_ hard code a maximum, but I was looking for the 'ideal' answer.
;-)   I'd like to find out how to assign an array size at runtime, but
couldn't grasp dynamic arrays in the context below.
        Thanks for your reply.
Quote
On Wed, 21 Mar 2001 17:54:27 -0800, Ralf Quint <ralf_qu...@hotmail.com> wrote:
>On Thu, 22 Mar 2001 00:44:57 GMT, bn...@XXXsympatico.ca wrote:

>>        I'm trying to replicate my tiny Clipper app that reads a data stream file
>>(no CR or LFs) and writes it out to a text file with hard returns, but I've
>>hit a snag.
>>        The user needs to supply the line length, anywhere from 10 to 300 bytes.
>>The code below works for a fixed size "Buf", but I can't use a variable in the
>>array declaration, and I gave up on dynamic arrays because frankly, I don't
>>know what I'm doing.  ;-)
>>        Any help, or alternative read/write methods, would be Greatly appreciated!
>>    (I'm using D4.)

>>-----------------
>>var
>>  InFile: file;
>>  OutFile: TextFile;
>>  Buf: array[1..29] of Char;    <--------- How do I make this value variable?
>Why don't you just provide the maximum line length for the buffer (if
>it's a maximum of 300 bytes, that doesn't "cost" you anything

>>begin
>>  AssignFile(OutFile, 'd:\output.txt');
>>  Rewrite(OutFile);
>>  AssignFile(InFile, 'd:\input.tbl');
>>  Reset(InFile, 1);

>>  while not Eof(InFile) do
>>  begin
>>    BlockRead(InFile, Buf, SizeOf(Buf));
>>    WriteLn(OutFile, Copy(Buf, 1, 29));    <-- this line is a problem too...
>And then use the "variable" line length to read and write the lines,
>like

>BlockRead (Infile, Buf, LineLength);
>WriteLn (OutFile, Copy (Buf, 1, LineLength));
>>  end;
>>  CloseFile(InFile);
>>  CloseFile(OutFile);
>>  showmessage('done');

>or do i miss something (beside i don't know right out of my head if
>the Copy function on the buffer works on more than 255 bytes in D4 (it
>does in D5))

>Ralf

Re:Read data file; write text file


        The problem with this solution (unless I'm not thinking straight) is that
BlockRead is going to be reading 300 bytes at a time, while I might need only
80 characters written out (as a line of text with CR/LF.)  That leaves 220
bytes in the buffer that I'll lose on the next read.
Quote
On Wed, 21 Mar 2001 17:54:27 -0800, Ralf Quint <ralf_qu...@hotmail.com> wrote:
>On Thu, 22 Mar 2001 00:44:57 GMT, bn...@XXXsympatico.ca wrote:

>>        I'm trying to replicate my tiny Clipper app that reads a data stream file
>>(no CR or LFs) and writes it out to a text file with hard returns, but I've
>>hit a snag.
>>        The user needs to supply the line length, anywhere from 10 to 300 bytes.
>>The code below works for a fixed size "Buf", but I can't use a variable in the
>>array declaration, and I gave up on dynamic arrays because frankly, I don't
>>know what I'm doing.  ;-)
>>        Any help, or alternative read/write methods, would be Greatly appreciated!
>>    (I'm using D4.)

>>-----------------
>>var
>>  InFile: file;
>>  OutFile: TextFile;
>>  Buf: array[1..29] of Char;    <--------- How do I make this value variable?
>Why don't you just provide the maximum line length for the buffer (if
>it's a maximum of 300 bytes, that doesn't "cost" you anything

>>begin
>>  AssignFile(OutFile, 'd:\output.txt');
>>  Rewrite(OutFile);
>>  AssignFile(InFile, 'd:\input.tbl');
>>  Reset(InFile, 1);

>>  while not Eof(InFile) do
>>  begin
>>    BlockRead(InFile, Buf, SizeOf(Buf));
>>    WriteLn(OutFile, Copy(Buf, 1, 29));    <-- this line is a problem too...
>And then use the "variable" line length to read and write the lines,
>like

>BlockRead (Infile, Buf, LineLength);
>WriteLn (OutFile, Copy (Buf, 1, LineLength));
>>  end;
>>  CloseFile(InFile);
>>  CloseFile(OutFile);
>>  showmessage('done');

>or do i miss something (beside i don't know right out of my head if
>the Copy function on the buffer works on more than 255 bytes in D4 (it
>does in D5))

>Ralf

Re:Read data file; write text file


Quote
<bn...@XXXsympatico.ca> wrote in message

news:bpiibt8mkil1mk333e5r7r5h8d04671213@4ax.com...

Quote
> I'm trying to replicate my tiny Clipper app that reads a data stream file
> (no CR or LFs) and writes it out to a text file with hard returns, but
I've
> hit a snag.
> The user needs to supply the line length, anywhere from 10 to 300 bytes.
> The code below works for a fixed size "Buf", but I can't use a variable in
the
> array declaration, and I gave up on dynamic arrays because frankly, I
don't
> know what I'm doing.  ;-)
> Any help, or alternative read/write methods, would be Greatly appreciated!

procedure CopyAndBreakFile (src, dst : String; lineLength : integer);

var    inFile,
        outFile        : tFileStream;
        buf             : string;

begin
inFile := tFileStream.Create (src, fmOpenRead or fmShareCompat);
try
    outFile := tFileStream.Create (dst, fmOpenWrite or fmShareExclusive);
    try
        SetLength (buf, lineLength + 2);
        buf [lineLength + 1] := #13;
        buf [lineLength + 2] := #10;
        while inFile.Position < inFile.Size do
            begin
            inFile.Read (buf [1], lineLength);
            outFile.Write (buf [1], lineLength + 2);
            end;
    finally
        outFile.Free;
        end;
finally
    inFile.Free;
    end;
end;

Re:Read data file; write text file


Quote
On Thu, 22 Mar 2001 03:33:26 GMT, bn...@XXXsympatico.ca wrote:
>    The problem with this solution (unless I'm not thinking straight) is that
>BlockRead is going to be reading 300 bytes at a time, while I might need only
>80 characters written out (as a line of text with CR/LF.)  That leaves 220
>bytes in the buffer that I'll lose on the next read.

???? Sorry, i don't understand this???
You define the buffer size for the maximum possible, but you tell the
BlockRead exactly how many characters to read (LineLength). So why are
you losing something here???? (You defined already that BlockRead is
reading with a BlockSize of 1 Byte!)

<snip>

Quote
>>>var
>>>  InFile: file;
>>>  OutFile: TextFile;
>>>  Buf: array[1..29] of Char;    <--------- How do I make this value variable?
>>Why don't you just provide the maximum line length for the buffer (if
>>it's a maximum of 300 bytes, that doesn't "cost" you anything

>>>begin
>>>  AssignFile(OutFile, 'd:\output.txt');
>>>  Rewrite(OutFile);
>>>  AssignFile(InFile, 'd:\input.tbl');
>>>  Reset(InFile, 1);

Ok, BlockSize is 1 Byte...
Quote

>>>  while not Eof(InFile) do
>>>  begin
>>>    BlockRead(InFile, Buf, SizeOf(Buf));
>>>    WriteLn(OutFile, Copy(Buf, 1, 29));    <-- this line is a problem too...
>>And then use the "variable" line length to read and write the lines,
>>like

>>BlockRead (Infile, Buf, LineLength);

And you read LineLength number of bytes, so what is the problem????

Ralf

PS: If you really want to make it a dynamical buffer size you could do
it the following way, but for just up to 300 bytes, it's probably not
worth the hassle:

Type BufferType : Array [1..32000] of Char; (* that would be enough
for a really large line *)
Type   BufferPtr = ^BufferType;
Var Buf : BufferPtr;
....
begin
  ...
  GetMem (BufferPtr, LineLength); (* get the matching amount of
bytes/chars for the buffer *)
...
while...
   begin
      BlockRead (InFile, Buf^, LineLength);
     WriteLn (OutFile, Copy (Buf^, 1, LineLength);
   end;
  FreeMem (BufferPtr, LineLength); (* get rid of the buffer again *)

end.

  BlockRead (InFile

Re:Read data file; write text file


Quote
On Thu, 22 Mar 2001 00:44:57 GMT, bn...@XXXsympatico.ca wrote:
>    I'm trying to replicate my tiny Clipper app that reads a data stream file
>(no CR or LFs) and writes it out to a text file with hard returns, but I've
>hit a snag.
>    The user needs to supply the line length, anywhere from 10 to 300 bytes.
>The code below works for a fixed size "Buf", but I can't use a variable in the
>array declaration, and I gave up on dynamic arrays because frankly, I don't
>know what I'm doing.  ;-)
>    Any help, or alternative read/write methods, would be Greatly appreciated!
>    (I'm using D4.)

>-----------------
>var
>  InFile: file;
>  OutFile: TextFile;
>  Buf: array[1..29] of Char;    <--------- How do I make this value variable?

You can't, but you can do this:

  Buf: PChar;
  BufSize: Integer;

Quote
>begin
>  AssignFile(OutFile, 'd:\output.txt');
>  Rewrite(OutFile);
>  AssignFile(InFile, 'd:\input.tbl');
>  Reset(InFile, 1);

// somehow somewhere in here you have to get the
// "line length" into BufSize

   GetMem(Buf, BufSize + 1); // allow space for a null terminator

Quote

>  while not Eof(InFile) do
>  begin
>    BlockRead(InFile, Buf, SizeOf(Buf));

   BlockRead(InFile, Buf^, BufSize); // that dereference operator "^"
                                     // is  important! It's not a typo
   Buf[BufSize+1] := #0;  // add null terminator

Quote
>    WriteLn(OutFile, Copy(Buf, 1, 29));    <-- this line is a problem too...

   WriteLn(OutFile, Buf); // WriteLn works with null terminated
                          // arrays of char

Quote
>  end;

   FreeMem(Buf, BufSize + 1); // free your buffer

Quote
>  CloseFile(InFile);
>  CloseFile(OutFile);
>  showmessage('done');

>bn...@XXXsympatico.ca  (remove XXX to reply)      

Feel free to Email me directly if this doesn't make sense or you have
other problems implementing this.  We could also talk about using
FileStreams for this as well.

HTH

Stephen Posey
slpo...@concentric.net

Re:Read data file; write text file


In article <rHeu6.12249$TW.48...@tor-nn1.netcom.ca>, "Bruce Roberts"

Quote
<b...@bounceitattcanada.xnet> writes:
><bn...@XXXsympatico.ca> wrote in message
>news:bpiibt8mkil1mk333e5r7r5h8d04671213@4ax.com...
>> I'm trying to replicate my tiny Clipper app that reads a data stream file
>> (no CR or LFs) and writes it out to a text file with hard returns, but
>I've
>> hit a snag.

> <snip some good code from Bruce>

Recently I've been doing some work using wave files and  MMIO (MultiMedia I/O)
functions which have an automatically implemented I/O buffer so I thought I
would do a few time comparisons on breaking a 1.7Mb file into 100 character
lines using Bruce's code, similar code using a memory stream, and MMIO
functions.

The results (500Mhz, Win 98SE, 256Mb RAM, 2Mb cache on DMA 66 IBM HD) are as
follows in millisecs with the first figure being directly after a reboot, the
next is an average of a further five copies without a reboot ...

File Stream  1785 mSecs, 1582 mSecs

MemoryStream  512 mSecs, 144 mSecs

MMIO  226 mSecs, 88 mSecs

With just reload of the splitting program, the second figures are obtained
immediately. I guess that the reduction comes from the large HD cache, although
loading some large files in an attempt to flush the cache made little
difference.

Timer was a QP timer, code for mmio as follows ...

uses
  MMSystem;

procedure CopyAndBreakMMIO(Src, Dst : string; lineLength : integer);
var
  InFile, OutFile : hMMIO;
  Buf : string;
begin
  InFile := mmioOpen(PChar(Src), nil,
                    MMIO_READ or MMIO_COMPAT
                    or MMIO_ALLOCBUF) ;
  try
    OutFile := mmioOpen(PChar(Dst), nil,
                        MMIO_WRITE or MMIO_CREATE or MMIO_EXCLUSIVE
                        or MMIO_ALLOCBUF) ;
    try
      SetLength (Buf, LineLength + 2);
      Buf [LineLength + 1] := #13;
      Buf [LineLength + 2] := #10;
      mmioSeek(InFile, 0, SEEK_SET);
      while (mmioRead(InFile, @Buf[1], LineLength) > 0) do
        mmioWrite(OutFile, @Buf[1], LineLength + 2);
    finally
      mmioClose(OutFile, 0);
    end;
  finally
    mmioClose(InFile, 0);
  end;
end;

Alan Lloyd
alangll...@aol.com

Re:Read data file; write text file


Quote
"AlanGLLoyd" <alangll...@aol.com> wrote in message

news:20010322064926.13719.00000039@nso-fq.aol.com...

Quote
> File Stream  1785 mSecs, 1582 mSecs

> MemoryStream  512 mSecs, 144 mSecs

Did you use one or two memory streams? (For those that don't know:
tMemoryStream has LoadFrom/SaveToFile methods.)

Quote

> MMIO  226 mSecs, 88 mSecs

I wonder if the o/s has some bias in favor of multi-media requests to boost
their performance, or if the significantly better performance is strictly in
the MMIO code? In any case, Alan, you've just added another tool to my
toolbox. Thanks.

Re:Read data file; write text file


In article <Xkpu6.12321$TW.49...@tor-nn1.netcom.ca>, "Bruce Roberts"

Quote
<b...@bounceitattcanada.xnet> writes:
>> MemoryStream  512 mSecs, 144 mSecs

>Did you use one or two memory streams? (For those that don't know:
>tMemoryStream has LoadFrom/SaveToFile methods.)

Two - all that shuffling about with Seek(s) would make my brain hurt <gg>

BTW I have a small help file on streams if anyone would like it - e-mail me.

Quote

>> MMIO  226 mSecs, 88 mSecs

>I wonder if the o/s has some bias in favor of multi-media requests to boost
>their performance, or if the significantly better performance is strictly in
>the MMIO code?

I reckon its mainly due to the buffer (8k by default)

MMIO also has great stuff for dealing with chunks in a RIFF file if you have to
handle those. Its all in MMSystem.hlp or Multimedia.hlp.

Alan Lloyd
alangll...@aol.com

Re:Read data file; write text file


        I just slapped myself on the side of the head.  It's clear now.  Thanks
Ralf.
Quote
On Wed, 21 Mar 2001 20:28:33 -0800, Ralf Quint <ralf_qu...@hotmail.com> wrote:
>On Thu, 22 Mar 2001 03:33:26 GMT, bn...@XXXsympatico.ca wrote:

>>        The problem with this solution (unless I'm not thinking straight) is that
>>BlockRead is going to be reading 300 bytes at a time, while I might need only
>>80 characters written out (as a line of text with CR/LF.)  That leaves 220
>>bytes in the buffer that I'll lose on the next read.

>???? Sorry, i don't understand this???
>You define the buffer size for the maximum possible, but you tell the
>BlockRead exactly how many characters to read (LineLength). So why are
>you losing something here???? (You defined already that BlockRead is
>reading with a BlockSize of 1 Byte!)

><snip>
>>>>var
>>>>  InFile: file;
>>>>  OutFile: TextFile;
>>>>  Buf: array[1..29] of Char;    <--------- How do I make this value variable?
>>>Why don't you just provide the maximum line length for the buffer (if
>>>it's a maximum of 300 bytes, that doesn't "cost" you anything

>>>>begin
>>>>  AssignFile(OutFile, 'd:\output.txt');
>>>>  Rewrite(OutFile);
>>>>  AssignFile(InFile, 'd:\input.tbl');
>>>>  Reset(InFile, 1);
>Ok, BlockSize is 1 Byte...

>>>>  while not Eof(InFile) do
>>>>  begin
>>>>    BlockRead(InFile, Buf, SizeOf(Buf));
>>>>    WriteLn(OutFile, Copy(Buf, 1, 29));    <-- this line is a problem too...
>>>And then use the "variable" line length to read and write the lines,
>>>like

>>>BlockRead (Infile, Buf, LineLength);
>And you read LineLength number of bytes, so what is the problem????

>Ralf

>PS: If you really want to make it a dynamical buffer size you could do
>it the following way, but for just up to 300 bytes, it's probably not
>worth the hassle:

>Type BufferType : Array [1..32000] of Char; (* that would be enough
>for a really large line *)
>Type   BufferPtr = ^BufferType;
>Var Buf : BufferPtr;
>....
>begin
>  ...
>  GetMem (BufferPtr, LineLength); (* get the matching amount of
>bytes/chars for the buffer *)
>...
>while...
>   begin
>      BlockRead (InFile, Buf^, LineLength);
>     WriteLn (OutFile, Copy (Buf^, 1, LineLength);
>   end;
>  FreeMem (BufferPtr, LineLength); (* get rid of the buffer again *)

>end.

>  BlockRead (InFile

Re:Read data file; write text file


Quote
On Thu, 22 Mar 2001 23:06:51 GMT, bn...@XXXsympatico.ca wrote:
>    I just slapped myself on the side of the head.  It's clear now.  Thanks
>Ralf.

No problem, i know myself that sometimes, you have a few minutes
where..... ;-)))

take care,

Ralf

Re:Read data file; write text file


In article <Xkpu6.12321$TW.49...@tor-nn1.netcom.ca>, "Bruce Roberts"

Quote
<b...@bounceitattcanada.xnet> writes:
>Did you use one or two memory streams? (For those that don't know:
>tMemoryStream has LoadFrom/SaveToFile methods.)

After I sent the last post I realised (and I sure you do now) that you can only
use just one stream if you are generating a shorter stream, not if you're
generating a longer stream. Or rather, its an _aweful, awful, mind-boggling_
lot of work (and I'm sure slower) to use only one stream when making a longer
stream.

<gg>

Alan Lloyd
alangll...@aol.com

Re:Read data file; write text file


Quote
"AlanGLLoyd" <alangll...@aol.com> wrote in message

news:20010323060733.13666.00000120@nso-fs.aol.com...

Quote
> In article <Xkpu6.12321$TW.49...@tor-nn1.netcom.ca>, "Bruce Roberts"
> <b...@bounceitattcanada.xnet> writes:

> >Did you use one or two memory streams? (For those that don't know:
> >tMemoryStream has LoadFrom/SaveToFile methods.)

> After I sent the last post I realised (and I sure you do now) that you can
only
> use just one stream if you are generating a shorter stream, not if you're
> generating a longer stream. Or rather, its an _aweful, awful,
mind-boggling_
> lot of work (and I'm sure slower) to use only one stream when making a
longer
> stream.

Q&D, and not that pretty:

procedure CopyAndBreak (src, dst : string; lnLth : integer);

     procedure MoveSegment (var src, dst : pChar; cnt : integer);

     begin
     dst^ := #10;
     dec (dst);
     dst^ := #13;
     dec (dst);
    // could probably save some time using Move instead of loop
     while (cnt > 0)  do
          begin
          dst^ := src^;
          dec (dst);
          dec (src);
          dec (cnt);
          end;
     end;

var  ms : tMemoryStream;
     i,
     oldSz,
     lastSeg,
     numSegs,
     sz   : integer;
     eBuf,
     pBuf : pChar;

begin
ms := tMemoryStream.Create;
try
    ms.LoadFromFile (src);
    oldSz := ms.Size;
    numSegs := oldSz div lnLth;
    lastSeg := oldSz mod lnLth;
    if lastSeg > 0
    then inc (numSegs);
    sz := oldSz + (numSegs * 2);
    ms.SetSize (sz);
    pBuf := ms.Memory;
    eBuf := @pBuf [sz - 1];
    pBuf := @pBuf [oldSz - 1];
    if lastSeg > 0
    then MoveSegment (pBuf, eBuf, lastSeg);
    for i := 1 to (numSegs - 1) do
         MoveSegment (pBuf, eBuf, lnLth);
    eBuf^ := #10;
    dec (eBuf);
    eBuf^ := #13;
    ms.Position := 0;
    ms.SaveToFile (dst);
finally
    ms.Free;
    end;
end;

Re:Read data file; write text file


In article <dwNu6.12684$TW.51...@tor-nn1.netcom.ca>, "Bruce Roberts"

Quote
<b...@bounceitattcanada.xnet> writes:
>Q&D, and not that pretty:

>procedure CopyAndBreak (src, dst : string; lnLth : integer);

>     procedure MoveSegment (var src, dst : pChar; cnt : integer);

>     begin
>     dst^ := #10;
>     dec (dst);
>     dst^ := #13;
>     dec (dst);
>    // could probably save some time using Move instead of loop
>     while (cnt > 0)  do
>          begin
>          dst^ := src^;
>          dec (dst);
>          dec (src);
>          dec (cnt);
>          end;
>     end;

>var  ms : tMemoryStream;
>     i,
>     oldSz,
>     lastSeg,
>     numSegs,
>     sz   : integer;
>     eBuf,
>     pBuf : pChar;

>begin
>ms := tMemoryStream.Create;
>try
>    ms.LoadFromFile (src);
>    oldSz := ms.Size;
>    numSegs := oldSz div lnLth;
>    lastSeg := oldSz mod lnLth;
>    if lastSeg > 0
>    then inc (numSegs);
>    sz := oldSz + (numSegs * 2);
>    ms.SetSize (sz);
>    pBuf := ms.Memory;
>    eBuf := @pBuf [sz - 1];
>    pBuf := @pBuf [oldSz - 1];
>    if lastSeg > 0
>    then MoveSegment (pBuf, eBuf, lastSeg);
>    for i := 1 to (numSegs - 1) do
>         MoveSegment (pBuf, eBuf, lnLth);
>    eBuf^ := #10;
>    dec (eBuf);
>    eBuf^ := #13;
>    ms.Position := 0;
>    ms.SaveToFile (dst);
>finally
>    ms.Free;
>    end;
>end;

Pretty good ! ! <g> How does your brain feel now - just a {*word*249}y bit tired <gg>

I didn't (I think) say it was impossible, but I had a feeling that somehow it
didn't seem right. Having thought about it I realised why my intuitive and
ancient design sense was giving me bad vibes <g>.

It's that the number of bytes that you would normally copy increases as the
square of the file length, and that _is_ a Bad Thing. But you have quite
cleverly overcome that by increasing the memory allocated as the first step,
and then copying across from the end backwards. A good example of lateral
thinking and it just shows that it always wise to query intuitive stuff <g>.

BTW I think the CRLF at the end of the code (beginning of file) is not needed
and (I think) would overwrite memory prior to the stream.

Because this is not a usual implementation of copying I think it's one where I
would do quite a few comments

Alan Lloyd
alangll...@aol.com

Go to page: [1] [2]

Other Threads