SourcePoint Intel Help

Table of Contents

fread

Read binary data from a file into an array.

Syntax

[result =] fread(buffer, file_handle)

Where:

result

specifies a debug variable of type ord4 to which the function return value is assigned. If result is not specified, the return value is displayed on the next line of the screen.

buffer

is an array variable to receive the data read.

file_handle

is the file handle returned from a previous fopen command.

Discussion

The fread function reads binary data from a file previously opened by an fopen command. The data is stored in the array. ย The length of each item of data read is specified by the size of the array. The returned value is the number of items or data read.

Note: The feof command should be used to detect end of file.

Example

To read a binary file and write into target memory at address 0:

Command input:

define ord4 file1
define ord4 nItemsRead
define ord4 Buf[1000]
define ptr pMem = 0

ย 

file1 = fopen("test.dat", "r")

while (feof(file1) == 0)

{

ย ย ย nItemsRead = fread(Buf, file1)

ย ย ย ord1 pMem length nItemsRead = Buf

ย ย ย pMem += nItemsRead

}

fclose (file1)

Related Topics: