Chapter 9 File Processing 2017 – 2018, Semester 2 Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering Introduction to Computer Programming (C language) TS Võ Thị Ngọc[.]
Trang 1Chapter 9: File Processing
Introduction to Computer Programming
(C language)
TS Võ Thị Ngọc Châu (chauvtn@cse.hcmut.edu.vn,
chauvtn@hcmut.edu.vn)
Trang 2Course Content
Programming
Components
Trang 3References
Deitel and Harvey Deitel, Prentice Hall, 2012
– Brian W Kernighan and Dennis M Ritchie, Prentice Hall, 1988
Trang 44
Content
Introduction
Declare files
Open and close files
Store and retrieve data from files
Use macros
Summary
Trang 5Recall – Chapter 3 and Chapter 8
Uninitialized data
.bss
Initialized data
.data
Code
.text
Stack
Heap
Read from program file
by exec
Initialized to
zero by exec
Command-line arguments
and environment variables
Higher address
Lower address
Local variables, arguments,
grown/shrunk with function calls
Grown/shrunk with dynamic
allocation and de-allocation
Uninitialized (static) global
variables, static local variables
Initialized (static) global variables,
static local variables, constants
Machine code, often read-only
Trang 6Introduction
Temporary as lost when a program terminates !!!
after program execution?
drives, CDs, DVDs, flash drives, …)
6
Trang 7Introduction
Files on hard drives
data1.txt data2.txt
…
Trang 8Introduction
8
Figure 11.1 Data hierarchy
[1], pp 419
Trang 9Introduction
a specific byte number recorded in a
system-maintained, administrative data structure
file
files and programs
Figure 11.2 C’s view of a file of n bytes
Trang 10Introduction
bytes
beginning of the file
10
Figure 11.10: C’s view of a random-access file
[1], pp 431