Get & Put in turbo pascal 
Author Message
 Get & Put in turbo pascal

   I am trying to write a procedure that will merge files together.
The files are of type record with three fields.  I know turbo Pascal
does not use the standard functions of Get and Put,  is there a way
around this?
         -Glenn


Wed, 18 Jun 1902 08:00:00 GMT  
 Get & Put in turbo pascal
:    I am trying to write a procedure that will merge files together.
: The files are of type record with three fields.  I know turbo pascal
: does not use the standard functions of Get and Put,  is there a way
: around this?

Use Read and Write, or BlockRead/BlockWrite.



Wed, 18 Jun 1902 08:00:00 GMT  
 Get & Put in turbo pascal

Quote:

>                           Get & Put in turbo pascal


>   Reply to: G. Lawrence
>   Date: 13 Apr 1996 06:21:08 GMT
>   Organization: CompuServe Incorporated
>   Newsgroups:
>          comp.lang.pascal.borland
>   Followup to: newsgroup(s)

>   I am trying to write a procedure that will merge files together.
>The files are of type record with three fields.  I know turbo pascal
>does not use the standard functions of Get and Put,  is there a way
>around this?
>         -Glenn

If you want to open the file and handle each record individually instead
of reading them in byte by byte, then something like this can be done:

type
  rectype=record
             {your record stuff}
          end;
  recfile=file of rectype;
var
  inf:recfile;
  rec:rectype;
.......

begin
  assign(inf,'record.dat');
  reset(inf);
  read(inf,rec);   { the entire record is read in }
  close(inf);
end.

*--------------------------------------------------------*
|                      Robert Wagner                     |

*--------------------------------------------------------*
|10101001000001100001110011111001101100000110011100100001|
*--------------------------------------------------------*



Wed, 18 Jun 1902 08:00:00 GMT  
 Get & Put in turbo pascal

Quote:

>   I am trying to write a procedure that will merge files together.
>The files are of type record with three fields.  I know turbo pascal
>does not use the standard functions of Get and Put,  is there a way
>around this?
>         -Glenn

This program will do your job no matter what type of data the files
contain as long as it is binary data. That means that ASCII files
cannot be merged by this routine because of the ^Z character.
          -Jes R Klinke

program MergeFiles;

var
  ReadBytes, WrittenBytes: Word;
  Buffer: array [0..2047] of Byte;
  Infile1, Infile2, Outfile: file;
  FileName: string;

begin
  Write('Name of first file to be merged: ');
  ReadLn(FileName);
  Assign(Infile1, FileName);
  Write('Name of second file to be merged: ');
  ReadLn(FileName);
  Assign(Infile2, FileName);
  Write('Name of output file: ');
  ReadLn(FileName);
  Assign(Outfile, FileName);
  Reset(Infile1, 1);
  Reset(Infile2, 1);
  Rewrite(Outfile, 1);
  repeat
    BlockRead(Infile1, Buffer, 2048, ReadBytes);
    BlockWrite(Outfile, Buffer, ReadBytes, WrittenBytes);
  until WrittenBytes = 0;
  repeat
    BlockRead(Infile2, Buffer, 2048, ReadBytes);
    BlockWrite(Outfile, Buffer, ReadBytes, WrittenBytes);
  until WrittenBytes = 0;
  Close(Infile1);
  Close(Infile2);
  Close(Outfile);
end.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Turbo Pascal gets 100% Windows NT CPU

2. Turbo Pascal gets 100% Windows NT CPU

3. Getting direct access to more than 1 Meg In Turbo Pascal

4. difference between TURBO PASCAL & BORLAND PASCAL

5. difference between TURBO PASCAL & BORLAND PASCAL

6. Turbo Pascal & Delphi

7. Turbo Pascal 7 & Blaise Power Tools challenge $$$

8. Turbo Pascal 1.5 & win 95

9. turbo pascal 1.5 & win95

10. Need Advice & WTB: Turbo Pascal 7

11. Turbo pascal & C language

12. Turbo Pascal & New Fonts

 

 
Powered by phpBB® Forum Software