File Operation: Following are the compulsory steps to operate files:
1. Create file.
2. Merging file i.e., combine records of two or more files into one.
3. Adding records.
4. Deleting records.
5. Update records.
6. Generate reports.
The ‘C’ language supports different level of file processing according to the environment used.
The general functions which are supported by ‘C’ in the file processing are:
- Input functions
- Output functions
fopen( ) is the main function to start the above given functions. To open a file, to create a file, to restart with existing file etc., are the main functions which are performed by it.
file pointer = fopen(filename, mode);
i.e., FILE *fp;
fp = fopen(TRY.C”, “r”);
fp is a pointer variable, which contains the address of the structure FILE which has been defined in the header file “stdio.h”.
fopen() will open a file TRY.C’ in ‘read* mode, which tells the C compiler that we would be reading the contents of the file, “r” is a string and not a character.
Hence, fopen() performs three important tasks when you open the file in “r” mode:
- It searches on the disk the file to be opened.
- If the file is present, it loads that file from the disk into memory.If the file is absent, fopen() returns a NULL. This function opens one file at a time.
- It sets up a character pointer which points to the first character of the memory where the file has been modified.