Syntax
fscanf(fp, “format string”, list);
where
list
is the list of addresses where the values are to be stored.
5.6 BLOCK (OR RECORD) I/O FUNCTIONS
Block or Record I/O functions are used to read or write a structure or an array from a file
.
These functions are basically used to read or write database files—for instance, if we want to read or
write a complete record of an employee from a file in the form of structure.
Writing Data to a File
To write a block of data into a file, we use the fwrite( ) function:
Syntax
fwrite (ptr, m, n, fp);
where
ptr
is an
address of a structure or an array written into a file
,
m
is the size of structure
or an array
,
n is the number of structures or arrays
to be written, and
fp is a file pointer.
After
writing the block, this function returns the number of data items written. If less than requested, an
error has occurred. In this case, the file must be opened in binary mode.
Do'stlaringiz bilan baham: |