File Handling in C
,What is a File?
• A file is a collection of related data that a
computers treats as a single unit.
• Computers store files to secondary storage so that
the contents of files remain intact when a
computer turns off.
• When a computer reads a file, it copies the file
from the storage device to memory; when it writes
to a file, it transfers data from memory to the
storage device.
• C uses a structure called FILE (defined in
stdio.h) to store the attributes of a file.
stdio.h
Computer System and programming in C
, Steps in Processing a File
1. Create the stream via a pointer variable using the
FILE structure:
FILE *p;
2. Open the file, associating the stream name with the
file name.
3. Read or write the data.
4. Close the file.
Computer System and programming in C
,What is a File?
• A file is a collection of related data that a
computers treats as a single unit.
• Computers store files to secondary storage so that
the contents of files remain intact when a
computer turns off.
• When a computer reads a file, it copies the file
from the storage device to memory; when it writes
to a file, it transfers data from memory to the
storage device.
• C uses a structure called FILE (defined in
stdio.h) to store the attributes of a file.
stdio.h
Computer System and programming in C
, Steps in Processing a File
1. Create the stream via a pointer variable using the
FILE structure:
FILE *p;
2. Open the file, associating the stream name with the
file name.
3. Read or write the data.
4. Close the file.
Computer System and programming in C