File Handling:
-File Handling is the concept in which we store our data in the form of the files.
Why we require File Handling ?
In many time, we require to store our generated data somewhere that's by we store data in files so that we can further use this data.
Basic opeartion in File Handling:
-Create File.
-Open File.
-Write in File.
-Read the File.
-Append in File.
-Close File.
File Handling in C:
File pointer:
-we need to create a file pointer that deal with the file data.
Syntax-
FILE *fp;
where,
fp is the file pointer name.
Different functions that are used in File Handling :
fopen() : to open or create a new File.
fclose() : to open a file.
fprintf() : to write data in the File.
fscanf() : to read data from the File.
fputc() : to write a character in the file.
fgetc() : to get a character from the file.
fseek() : set the file pointer to given position.
ftell() : to return current position.
rewind() : to set the file pointer at the begining of the file.
Different modes to open the file:
r : to open the file in read mode.
w : to open the file in write mode.
a : to open the file in append mode.
r+ : to open the file in read and write mode.
w+ : to open the file in read and write mode.
rb : to open the Binary file in read mode.
wb : to open the Binary file in write mode.
ab: to open the Binary file in append mode.