Difference between revisions of "BINWRITE()"

From Lianjapedia
Jump to: navigation, search
(Example)
 
Line 13: Line 13:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
fd = binopen("file.obj")
+
fd = binopen("file.obj", 2)
 
count = binread(fd, 4)
 
count = binread(fd, 4)
 
count = bin2l(count)
 
count = bin2l(count)

Latest revision as of 20:56, 28 February 2019

Purpose

Function to write an expression to a binary file

Syntax

BINWRITE(<expN>,<expC>)

See Also

BIN2I(), BIN2L(), BIN2W(), BINCLOSE(), BINCREATE(), BINOPEN(), BINREAD(), BINSEEK(), FWRITE(), I2BIN(), L2BIN()

Description

The BINWRITE() is used to write a character expression to a binary file, and returns the number of bytes written. The <expC> specifies the character expression to write to the binary file. The <expN> is the file descriptor of the file to write to. The file descriptor is obtained when the binary file is opened, as the return value from either the BINCREATE() or BINOPEN() functions. The BINWRITE() function writes the character expression starting at the position returned by the BINSEEK() function. The binary conversion functions may be used in conjunction with all the binary file functions.

Example

fd = binopen("file.obj", 2)
count = binread(fd, 4)
count = bin2l(count)
count = l2bin(count + 1)
binseek(fd, 512, 0)
binwrite(fd, count)
binclose(fd)