Advance C Project Chapter 2 (Introduction To File Handling in C-Part 1)
Advance C Project Chapter 2 (Introduction To File Handling in C-Part 1)
CHAPTER 2
FILE HANDLING BASICS
Topics Covered
• What Is File Handling?
• Why To Use File Handling?
• How C Handles Files ?
• Steps Required In File Handling
• File Opening Modes
What is a File?
• A file is a collection on information, usually
stored on a computer’s disk. Information can
be saved to files and then later reused.
3
Why We Need File Handling ?
• Files are places where data can be stored
permanently.
• Some programs expect the same set of data to be fed
as input every time it is run.
– Cumbersome.
– Better if the data are kept in a file, and the program
reads from the file.
• Programs generating large volumes of output.
– Difficult to view on the screen.
– Better to store them in a file for later viewing/
processing
How C Handles Files ?
• C uses a structure called FILE (defined in stdio.h) to store the
attributes of a file.
5
Steps in Processing a File
1. Create the stream via a pointer variable using the
FILE structure:
FILE* fp;