Read binary data from a file
UInt_Type fread (Ref_Type b, DataType_Type t, UInt_Type n, File_Type fp)
The fread function may be used to read n objects of type
t from an open file pointer fp. Upon success, it
returns the number of objects read from the file and places the
objects in the variable specified by b. Upon error or end of
file, it returns -1. If more than one object is read from the
file, those objects will be placed in an array of the appropriate
size. The exception to this is when reading Char_Type or
UChar_Type objects from a file, in which case the data will be
returned as an n character BString_Type binary string, but
only if n>1.
The following example illustrates how to read 50 bytes from a file:
define read_50_bytes_from_file (file)
{
variable fp, n, buf;
fp = fopen (file, "rb");
if (fp == NULL) error ("Open failed");
n = fread (&buf, Char_Type, 50, fp);
if (n == -1)
error ("fread failed");
() = fclose (fp);
return buf;
}
Use the pack and unpack functions to read data with a
specific byte-ordering.
- slangrtl
-
clearerr,
fclose,
fdopen,
feof,
ferror,
fflush,
fgets,
fgetslines,
fileno,
fopen,
fprintf,
fputs,
fseek,
ftell,
fwrite,
isatty,
mkdir,
open,
pack,
pad_pack_format,
popen,
printf,
read,
sizeof_pack,
sscanf,
uname,
unpack,
write
|