


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
file handling notes of c programming
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
In programming it is not enough to just display the data on the screen. Because if data is large then it will first take memory for store data then after it can be display on screen. For storing the data in memory today we learn file handling. In c programming two types of file on which we perform operation.
Binary File This file contain the information in the binary code like - (1 or 0) and it is only read my machine. It is represent by ( .bin ) extension.
Operation on file
File Mode Description
r
It opens an file for reading purpose. If file does not exist , fopen() return Null
r+
It opens an file read and write purpose. If file does not exist , fopen() return Null
w
it opens a text file for writing purpose. if file does not exist , then a new file is created. if file exists it content are overwritten.
it opens a text file for writing and reading purpose. if file does not exist , then a new file is created. if file exists it content are overwritten
a
It used to open a text file in writing append mode. If the file does not exist , then a new file is created
a+
It used to open a text file in reading and writing append mode. If the file does not exist , then a new file is created
Function in File handling
Function Name Description
fopen
Declaration: FILE *fopen (const char *filename, const char *mode) It is used to open a text file on given path It have two parameter where path (where file is created) and mode of operation FILE *fp; fp=fopen (“filename”, ”‘mode”);
fscanf
It is used to scan the file. It read a set of data from file.
fprintf
printf is used to print the information or data on output screen. fprintf is used to print information or data into the file. It has also two parameter file and message which is to be printed.
fclose
Declaration: int fclose(FILE *fp); It is used to close the file fclose (fp);
getc
Declaration: char *gets (char *string) It is used to get a character from file. gets (string);
putc
Declaration: int fputs (const char *string, FILE *fp) It is used to write a character to a file. fputs (fp, “some data”);
Program Example #include<stdio.h>