A file is a collection of data stored in a secondary storage device like hard disk. File is a readymade structure created for storing data permanently. A structure pointer of file type is used for declaring a file in c.
Syntax
FILE *fp;
After termination of a program the entire data is lost, but storing those data in a file will preserve them after the termination of the program also. Using a few commands in C all the contents of any file can be accessed easily.
There are a certain functions in c to perform basic file operations.
Function | Purpose |
---|---|
fopen() | It is used to open a file based on the file modes. Like (r, w, a, r+, a+, w+ etc.) |
fclose() | It is used to close an open file which disconnects a file pointer from a file. |