Input & Output Operations On File in C
Input & Output Operations On File in C
General Syntax:
*fp = FILE *fopen(const char *filename, const char *mode);
Here, *fp is the FILE pointer (FILE *fp), which will hold the reference to the opened(or created)
file.
filename is the name of the file to be opened and mode specifies the purpose of opening the file.
VARIOUS MODES OF OPENING A FILE
Mode Description
"r" To read a file. Opens a file for reading. The file must exist.
"w" To write on a file. Creates an empty file for writing. If a file already exists
with same name, its content is removed and the file is considered as a new
empty file.
"a" To append data at the end of file. The file is created if it does not exist.
"r+" To read and write on an existing file. Opens a file to update both reading and
writing. The file must exist.