opening file in C

the fopen() function in c programming language is used to open any file to view or edit or append according to given mode.Following is how to declare fopen() function and how to declare it.

Declaration:
FILE *fopen(const char *filename,const char *mode);

there are two types of parameters in fopen function they are filename and in which mode we have to open it.Following are some modes to open file by fopen() function in c programming language.

Mode

Description


r
This mode is used to read the file

w
this mode is used to write the file and if it is already exist then it will delete old contents and create new file.

a
this mode is used to append the data to the end of the file and if it doesn't exist then it will create new file.

r+
Open a file for update both reading and writing but The file must exist
w+create an empty file for both reading and writing.
a+open a file for reading and appendng.