Board index » delphi » PLEASE: could someone email me an algorithm using binary files....C description

PLEASE: could someone email me an algorithm using binary files....C description

Please email me an algorithm that writes records to a binary file.  It
would be great if it read the input from a text file then converted it
into files, and finally wrote it into the binary file.

Thank you in advance!

 

Re:PLEASE: could someone email me an algorithm using binary files....C description


On Sun, 28 Apr 1996 13:40:41 -0400, The Phantom Surfer <fsa00...@wvnvm.wvnet.edu> said...

Quote
>Please email me an algorithm that writes records to a binary file.  It
>would be great if it read the input from a text file then converted it
>into files, and finally wrote it into the binary file.

Are you trying to make this too hard?  

   type tmyrecordtype = record {field declarations} end;
        pmyrecordtype = ^tmyrecordtype;
   type myrecordfunc = function (pmyrecordtype):pmyrecordtype;

   procedure write_myrecordtype_file(const filename:string; nextrecord: myrecordfunc);
   { write a binary file of records from whatever source the function nextrecord uses. }
   { nextrecord(NIL) should return address of the first record to written. }
   { nextrecord(@arecord) should return the address of the record following arecord. }
   { nextrecord should return NIL when no more record are available. }
   var fo:file of tmyrecordtype;
       current:pmyrecordtype;
   begin
      assign(fo,filename);
      rewrite(fo);
      current:=nextrecord(NIL); {get first record to write}
      while (current<>NIL) do begin
         write(fo,current^);
         current:=nextrecord(current); {get next record to write}
      end;
      close(fo);      
   end;

Other Threads