UNIT V FILE PROCESSING
Files – Types of file processing: Sequential
access, Random access – Sequential access file –
Random access file – Command line arguments.
Files
• A file is a semi-permanent,(Semi-permanent means that data
saved in files stays safe until it is deleted or modified) named
collection of data(Named means that a particular collection of
data on a disk has a name, like mydata.dat and access to the
collection is done by using its name.)
• A File is usually stored on magnetic media, such as a hard disk
or magnetic tape,A file represents a sequence of bytes on the
disk where a group of related data is stored. File is created for
permanent storage of data. It is a readymade structure .
Types of file
Text files Binary files
A text file consists of consecutive A binary file consists of bytes of data
characters, which are interpreted by arranged in continuous block. A
the library functions used to access separate set of library functions is there
them and by format specifiers used to process such data files. Binary files
in functions. Text files are the are mostly the .bin files in your
normal .txt files that you can easily computer. Instead of storing data in
create using Notepad or any simple plain text, they store it in the binary
text editors. They take minimum form (0's and 1's). They can hold
effort to maintain, are easily higher amount of data, are not readable
readable, and provide least security easily and provides a better security
and takes bigger storage space. than text files.
File Operations
1. Creating a new file
2. Opening an existing file
3. Closing a file
4. Reading from and writing information to a file
The w mode means that the file is
opened for writing. To insert content
to it, you can use
the fprintf() function and add the
pointer variable (fptr in our
example) and some text:
What is a Sequential File?
A sequential file is a type of file structure used in computer systems to
organize and store data in a sequential order. In a sequential file,
records are stored one after another, with each new record being
appended to the end of the file. This means that the records are stored
in the order they are added, and accessing the data follows a
sequential pattern from the beginning to the end of the file
What is a Random Access File?
A random access file is a type of file structure that allows direct access to
any record within the file, enabling efficient searching, updating, and
retrieval of individual records. Unlike sequential access files where data is
organized and accessed sequentially, random access files provide the ability
to access records in any order based on their position or key