Some applications involve the use of data files to store blocks of data, where each block consists of a fixed number of contiguous bytes. Each block will generally represent a complex data structure, such as a structure or an array.For example, a data file may consist of multiple structures having the same composition, or it may contain multiple arrays of the same type and size. For such applications it may be desirable to read the entire block from the data file, or write the entire block to the data file, rather than reading or writing the individual components (i.e. structure members or array elements) within each block separately.
The library function fread and fwrite are used in this kind of situations. These functions are often referred to as unformatted read and write functions.Similarly, data files of this type are often referred to as unformatted data files.
Each of these functions require four arguments: a pointer to the data block, the size of the data block, the number of data blocks being transferred, and the stream pointer. Thus a typical fwrite function can be written as
fwrite (&customer, sizeof (record), 1, fpt);
where customer is a structure variable of type record, and fpt is the stream pointer associated with a data file that has been opened for output.
Monday, January 11, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment