Saturday, May 10, 2008

Processing a data file

Processing a data file

Most data file applications require that a data file be altered as it is being processed.
For example, in an application involving the processing of customer records, it may be desirable to add new records
to the file there requirements in turn suggest several different computational strategies.
Another approach is to work with two different data
files- an old file and a new file. Each record is read from
the old file, updated as necessary, and then written to the new file.

When all of the records have been updated, the old file
is deleted or placed into archival storage and the new file
renamed. Hence, the new file become the struck for the next round of updates.

Historically, the origin of this method goes back to the
early days of computing, when data files were maintained on
magnetic tapes. The method is still used, however, because
it provides a series of old source.

File that can be used to generate a customer history.
The most recent source file can also be used to recreate
the current file if the current file is damaged or destroyed.

Unformatted data file

Some applications involve the use of data files to store
block 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 applicators it may be desirable to read the entire
block from the data, or write the entire block to the data
file, rather than reading or writing the individual
components (i.e., structure members of array elements)
within each block separately.


The library functions fread and fwrite are intended to
be used in situations of this type.


There functions are often referred to as unformatted read
and write functions. Similarly, data files of this type are
often referred to as unformatted data file.

Each of these functions requires 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 might 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.

An example program to create an unformatted data file
containing customer records:



Reading file:

Displaying the contents:

2 comments:

Anonymous said...

Thanks for sharing this link, but argg it seems to be offline... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if someone here at c-codin.blogspot.com could repost it.

Thanks,
James

Anonymous said...

I know this web page presents quality depending posts and extra material, is there any other site which offers these information in quality?


Check out my website ... card sharing how to

Copyright

Copyright © 2008 C Tutorial, All rights are reserved