Chapter 11 - File Processing: Outline
Chapter 11 - File Processing: Outline
Outline
11.1 Introduction
11.2 The Data Hierarchy
11.3 Files and Streams
11.4 Creating a Sequential Access File
11.5 Reading Data from a Sequential Access File
11.6 Updating Sequential Access Files
11.7 Random Access Files
11.8 Creating a Random Access File
11.9 Writing Data Randomly to a Random Access File
11.10 Reading Data Sequentially from a Random
Access File
11.11 Example: A Transaction Processing Program
11.12 Input/Output of Objects
1 Bit
• Record key
– Identifies a record to facilitate the retrieval of specific records from
a file
• Sequential file
– Records typically sorted by key
2000 Prentice Hall, Inc. All rights reserved.
11.3 Files and Streams
• C views each file as a sequence of bytes
– File ends with the end-of-file marker
• Or, file ends at a specified byte
• Stream created when a file is opened
– Provide communication channel between files and programs
– Opening a file returns a pointer to a FILE structure
• Example file pointers:
• stdin - standard input (keyboard)
• stdout - standard output (screen)
• stderr - standard error (screen)
• FILE structure
– File descriptor - Index into operating system array called the open
file table
– File Control Block (FCB) - Found in every array element, system
uses it to administer the file
• Details
– Programs may process no files, one file, or many files
– Each file must have an unique name and will have a different
pointer
• All file processing must refer to the file using the pointer
Mode Desc ription
? 2
? 3
} byte offsets
}
}
}
}
}
}
100 100 100 100 100 100
bytes bytes bytes bytes bytes bytes
34 }
Outline
35
36 fclose( cfPtr );
3. Close file
37 }
38
39 return 0;
40 }
34 }
Outline
35
• We will
– Update existing accounts
– Add new accounts
– Delete accounts
– Store a formatted listing of all accounts in a text file
163 }
164
166 {
168
178
} 2000 Prentice Hall, Inc. All rights reserved.
After choosing option 1 accounts.txt contains:
Outline
Acct Last Name First Name Balance
29 Brown Nancy -24.54
33 Dunn Stacey 314.33 Program Output
37 Barker Doug 0.00
88 Smith Dave 258.34
96 Stone Sam 34.98