LIVE Course for free

Rated by 1 million+ students
Get app now
0 votes
in Computer by (45.8k points)
closed by

Discuss different file operations of ‘C’.

1 Answer

+1 vote
by (45.4k points)
selected by
Best answer

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

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.

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.