Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

File Handling Lecture Slides, Lecture notes of C programming

Lecture slides of File Handling in C language.

Typology: Lecture notes

2020/2021

Uploaded on 05/04/2023

ishita-gupta-15
ishita-gupta-15 🇮🇳

1 document

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
File Input/Output
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download File Handling Lecture Slides and more Lecture notes C programming in PDF only on Docsity!

File Input/Output

Why files are needed?

  • When a program is terminated, the entire data is

lost. Storing in a file will preserve your data even if the program terminates.

  • If you have to enter a large number of data, it will

take a lot of time to enter them all. However, if you have a file containing all the data, you can easily access the contents of the file using a few commands in C.

  • You can easily move your data from one computer

to another without any changes.

  • While working with files, we need to declare a pointer

of type FILE structure. This declaration is needed for communication between the file and the program.

  • FILE *fp;
  • Opening a file is performed using the fopen() function

defined in the stdio.h header file.

  • fp = fopen("fileopen","mode"); - fopen( ) performs three important tasks when you

open the file in “r” mode:

  • Firstly it searches on the disk the file to be opened.
  • Then it loads the file from the disk into a place in memory called buffer.
  • It sets up a character pointer that points to the first character of the buffer.
  • When we have finished reading from the file,

we need to close it.

  • This is done using the function fclose( )

Counting Characters,

Tabs, Spaces,