Various File Opening Modes in C - C Reference

C examples for Reference:Language Reference

Introduction

Mode string Description
"r" Existing text file is opened for reading only. If specified text file doesn't exist then error is reported.
"rb" Existing binary file is opened for reading only. If specified binary file doesn't exist then error is reported.
"rt" Same as "r".
"r+" Existing text file is opened for reading as well as writing. If specified text file doesn't exist then error is reported.
"r+b"Existing binary file is opened for reading as well as writing. If specified binary file doesn't exist then error is reported.
"r+t"Same as "r+".
"w" Contents of specified text file are deleted and then it is opened for writing. If specified text file doesn't exist then it is created.
"wb" Contents of specified binary file are deleted and then it is opened for writing. If specified binary file doesn't exist then it is created.
"wt" Same as "w".
"w+" Contents of specified text file are deleted and then it is opened for writing as well as reading. If specified text file doesn't exist then it is created.
"w+b"Contents of specified binary file are deleted and then it is opened for writing as well as reading. If specified binary file doesn't exist then it is created.
"w+t"Same as "w+".
"a" Specified text file is opened for writing at the end of file (i.e., appending). If specified text file doesn't exist then it is created.
"ab" Specified binary file is opened for writing at the end of file (i.e., appending). If specified binary file doesn't exist then it is created.
"at" Same as mode "a".
"a+" Specified text file is opened for reading as well as writing at the end of file (i.e., appending). If specified text file doesn't exist then it is created.
"a+b"Specified binary file is opened for reading as well as writing at the end of file (i.e., appending). If specified binary file doesn't exist then it is created.
"a+t"Same as "a+".

Related Tutorials