Text File Modes in C

During programming text file can be opened for different purposes i.e. reading, writing or both. This is specified by using file modes. Different text file modes in C programming are tabulated below:

ModesPurpose
rOpen text file for reading only. The file must already exist.
wOpen text file for writing only. If the file specified already exists, its contents will be destroyed. If it does not exist it will be created.
aOpen text file for appending (i.e. adding data to the end of existing file). If it does not exist it will be created.
r+Open text file for both reading and writing. The file must already exist.
w+Open text file for both reading and writing. If the file exists, its content will be overwritten. If it does not exist it will be created.
a+Open text file for both reading and appending. If a file does not exist it will be created.