Professional Documents
Culture Documents
File Structures 1
File Structures 1
File structure
Is a combination of representations for data in
files
Operations for accessing data
Allows applications to read, write, modify data
Very important in needs of applications and
tremendous variety of applications
B.Meena,Asst.Prof.,IT Dept,ANITS
Applications
For representing a city region telephone network.
store a set of fixed key words which are referenced very
frequently.
represent an image in the form of a bitmap.
implement back functionality in the internet browser.
implement printer spooler so that jobs can be printed in the
order of their arrival.
record the sequence of all the pages browsed in one session.
store information about the directories and files in a system.
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS
In ubuntu
B.Meena,Asst.Prof.,IT Dept,ANITS
[Computer Memory]
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS
10
11
B.Meena,Asst.Prof.,IT Dept,ANITS
12
In c and cpp
C
FILE *fp
fp=fopen(student.txt,r);
student.txt
CPP
fstream f1;
f1.open(student.txt,ios::in);
B.Meena,Asst.Prof.,IT Dept,ANITS
13
Physical file :
Actually exists on the storage
File known by computer OS and appears in the directory
Logical file :
file seen by the program
Allows to describe the operations performed on physical
file
B.Meena,Asst.Prof.,IT Dept,ANITS
14
Opening Files
Once we have a logical file identifier hooked up to
a physical file or device,
need to declare what we intend to do with the
file:
Open an existing file
Create a new file
That makes the file ready to use by the program
We are positioned at the beginning of the file and
are ready to read or write.
B.Meena,Asst.Prof.,IT Dept,ANITS
15
B.Meena,Asst.Prof.,IT Dept,ANITS
16
B.Meena,Asst.Prof.,IT Dept,ANITS
17
B.Meena,Asst.Prof.,IT Dept,ANITS
18
B.Meena,Asst.Prof.,IT Dept,ANITS
19
Closing Files
B.Meena,Asst.Prof.,IT Dept,ANITS
20
Reading
Read(Source_file, Destination_addr, Size)
Source_file = location the program reads from,
i.e., its logical file name
Destination_addr = first address of the memory
block where we want to store the data.
Size = how much information is being brought
in from the file (byte count).
B.Meena,Asst.Prof.,IT Dept,ANITS
21
B.Meena,Asst.Prof.,IT Dept,ANITS
22
Writing
Write(Destination_file, Source_addr, Size)
Destination_file = the logical file name where the
data will be written.
Source_addr = first address of the memory block
where the data to be written is stored.
Size = the number of bytes to be written.
B.Meena,Asst.Prof.,IT Dept,ANITS
23
B.Meena,Asst.Prof.,IT Dept,ANITS
24
Seeking
A program does not necessarily have to read through a
file sequentially: It can jump to specific locations in the file
or to the end of file so as to append to it.
The action of moving directly to a certain position in a file
is often called seeking.
Seek(Source_file, Offset)
Source_file = the logical file name in which the seek will occur
Offset = the number of positions in the file the pointer is to be
moved from the start of the file.
B.Meena,Asst.Prof.,IT Dept,ANITS
25
B.Meena,Asst.Prof.,IT Dept,ANITS
26
B.Meena,Asst.Prof.,IT Dept,ANITS
27
B.Meena,Asst.Prof.,IT Dept,ANITS
28
B.Meena,Asst.Prof.,IT Dept,ANITS
29
B.Meena,Asst.Prof.,IT Dept,ANITS
30
B.Meena,Asst.Prof.,IT Dept,ANITS
31
B.Meena,Asst.Prof.,IT Dept,ANITS
32
B.Meena,Asst.Prof.,IT Dept,ANITS
33
B.Meena,Asst.Prof.,IT Dept,ANITS
34
B.Meena,Asst.Prof.,IT Dept,ANITS
35
36
B.Meena,Asst.Prof.,IT Dept,ANITS
37
B.Meena,Asst.Prof.,IT Dept,ANITS
38
Text book
B.Meena,Asst.Prof.,IT Dept,ANITS
39
Assignment
Look up the operations equivalent to
open,close,create,read,write, seek in
COBOL,Ada,Fortran. compare them with c and c++
How do you use fseek, illustrate
What is the difference between pmode,O_RDWR
A couple of years ago a company bought a new cobol
compiler . One difference between the new compiler
and old one is , it did not automatically close files
when program execution terminates , where as old
compiler did . What sorts of problems would this cause
?
B.Meena,Asst.Prof.,IT Dept,ANITS
40
41