File Handling Chapter -13-Converted
File Handling Chapter -13-Converted
Disk
Input/Output
Text Binary
File input
File output
fgetc()
fputc()
fgets() File output File input
fputs()
fprintf() fscanf()
Page no. -1
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA) 9088134887
Page no. -2
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA) 9088134887
Page no. -3
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA) 9088134887
fopen() – To open a file Declaration: FILE *fopen (const char *filename, const char
*mode)
fopen() function is used to open a file to perform operations such
as reading, writing etc. In a C program, we declare a file pointer
and use fopen() as below. fopen() function creates a new file if the
mentioned file name does not exist.
FILE *fp;
fp=fopen (“filename”, ”‘mode”);
Where,
fp – file pointer to the data type “FILE”.
filename – the actual file name with full path of the file.
mode – refers to the operation that will be performed on the file.
Example: r, w, a, r+, w+ and a+. Please refer below the
description for these mode of operations.
fgets() – To read a file Declaration: char *fgets(char *string, int n, FILE *fp)
fgets function is used to read a file line by line. In a C program,
we use fgets function as below.
fgets (buffer, size, fp);
where,
buffer – buffer to put the data in.
size – size of the buffer
fp – file pointer
C programming language offers many inbuilt functions for handling files. They are given below. Please click on each
function name below to know more details, example programs, output for the respective file handling function.
Page no. -4
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA) 9088134887
getw () getw () function reads an integer from file.
fgets () fgets () function reads string from a file, one line at a time.
Page no. -5