TIP: Click on subject to list as thread! ANSI
echo: z3_pascal
to: Brad Boyd
from: Bob Lawrence
date: 1996-08-09 14:25:42
subject: binary

BB> My program writes text to a file and I was wondering how do I
 BB> save the file as a binary file? Any assistance would be
 BB> appreciated.

  How the file is saved or written does not change the content of the
file. It will still have the same ASCII characters in it. All that
changes is the way you put stuff in the file and retrieve it. The text
file format is handy if the content is lines of text, but you can save
text in binary format too... although not quite as easily. Exactly the
same stuff is in the file. It's not in code or anything...

  You declare the file type with the variable...

var
  F:  text;             makes the F handle a text file
  F:  file;             makes it an untyped binary file

  You assign the file handle the same way...

  Assign(F, 'c:\test.fle');
  but the text file procedures WriteLn(F, buf); ReadLn(F, buf) don't
work with a binary untyped file, and you have to state the size of the
block when you open the file with a binary file...

  Instead of   ReWrite(F);  for text, you put   ReWrite(F, 1);

  whcich means 1 character at a time, or one block at a time.
 
  BlockWrite(F, buf, 128);  writes 128 bytes to the file from buf
  BlockWrite(F, buf, 1);    writes one character to the file from buf
  BlockRead(F, buf, 128);   reads 128 bytes out of the file into buf

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™.