Introduction to File Handling
Introduction to File Handling
We frequently use files for storing information which can be processed by our programs. In order to store information permanently and retrieve it we need to use files.
Every file you open has its own file pointer variable. When you wish to write to a file you specify the file by using its file pointer variable.
You declare these file pointer variables as follows:
FILE *fp;
The function fopen is one of the Standard Library functions and returns a file pointer which you use to refer to the file you have opened e.g.
fp = fopen( “prog.c”, “r”) ;
The above statement opens a file called prog.c for reading and associates the file pointer fp with the file.
When we wish to access this file for I/O, we use the file pointer variable fp to refer to it.