Showing posts with label Block Oriented Input/Output function. Show all posts
Showing posts with label Block Oriented Input/Output function. Show all posts

Saturday 31 March 2012

Block Oriented Input/Output function


Block Oriented Input/Output function

To write/read a block specific numbers of bytes from / to a file block input/output functions are used.A block can read a record ,a set of records or an array.Normally these functions are used in case of binary files .

fwrite()

This function is used to write block of data to a file.
Syntax:

int fwrite(void *buf, int num_byte, int count ,fileptr);

Here,
buf is the pointer to the information to be written to the file. num_byte specifies number of bytes to be write. count specifies number of records to be write. Fileptr is the pointer to the file structure.
On success the number of elements writen is returned. On error the total number of elements successfully writen (which may be zero) is returned.
fread()

This function is used to read block of data from file.
Syntax:
int fread(void *buf, int num_byte, int count ,fileptr);

Here,
buf is the pointer to a memory area which receives the data from file. num_byte specifies number of bytes to be read. count specifies number of records to be read. Fileptr is the pointer to the file structure.
On success the number of elements read is returned. On error or end-of-file the total number of elements successfully read (which may be zero) is returned.

Posted By : Ruchita Pandya