Difference between revisions of "BINREAD()"

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", 0)
 
count = binread(fd, 4)
 
count = binread(fd, 4)
 
count = bin2l(count)
 
count = bin2l(count)

Revision as of 12:20, 26 February 2019

Purpose

Function to read a character string from a binary file

Syntax

BINREAD(<expN1>,<expN2>)

See Also

BIN2I(), BIN2L(), BIN2W(), BINCLOSE(), BINCREATE(), BINOPEN(), BINSEEK(), BINWRITE(), FREAD(), FREADSTR(), I2BIN(), L2BIN()

Description

The BINREAD() reads a character string from a binary file that was opened with the BINCREATE() or BINOPEN() functions. The <expN1> is the file descriptor which was returned when the file was opened with either the BINCREATE() or BINOPEN() functions. The <expN2> value represents the number of bytes to read. The BINREAD() function reads the specified number of bytes from the file starting at the current position of BINSEEK(). BINREAD() returns the character string in the specified length of <expN2> if successful, or a string of length zero if unsuccessful. The binary conversion functions may be used in conjunction with the binary file functions.

Example

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