Modes of fopen function in C language
A file modes allows to specify permissible operations when file opened in the C language. C provides many modes which can be used while opening file. It is also possible to combine different modes together or available which can be used in the program.

Modes of fopen function

r mode

A mode r is read only mode for text file which allows to read operation and place cursor at the beginning of the file to read.
Read mode
 1 // opening file in read only mode
 2 f = fopen("text.txt", "r");

w mode

A mode w is write only mode for text file which allows write operation and place cursor at the beginning of the file to write. If file already exist it overwrite otherwise create new file.
Write mode
 1 // opening file in write only mode
 2 f = fopen("text.txt", "w");

a mode

A mode a is write only mode for text file which allows to append file and place cursor at the end of file to append. If file already exist, it place cursor at the end of file otherwise create new file and place cursor at the beginning.
Append mode
 1 // opening file in append or write only mode
 2 f = fopen("text.txt", "w");

r+ mode

A mode r+ is read write mode is for text file which allows to read and write file and place cursor at the beginning of the file. It open file for read write mode only if file exist, It does not create new file if not exist.
Read write mode
 1 // opening file in read write mode
 2 f = fopen("text.txt", "r+");

w+ mode

A mode r+ is read write mode is for text file which allows to read and write file and place cursor at the beginning of the file. It open file for read write mode, if file exist, otherwise creates new file.
Read write mode
 1 // opening file in read write mode
 2 f = fopen("text.txt", "w+");

a+ mode

A mode a+ is read write mode for text file which allows to read and write file and place cursor at the end of file. It open file for append, if file exist, otherwise creates new file.
Read write mode
 1 // opening file in read write mode
 2 f = fopen("text.txt", "a+");

rb mode

A mode rb is read only mode for binary file which allows to read file and place cursor at the beginning of the file. It throws an error if file does not exist.
Read only mode
 1 // opening binary file in read only mode
 2 f = fopen("text.jpg", "rb");

wb mode

A mode wb is write only mode for binary file which allows to write file and place cursor at the beginning of the file. If file exist, it overwrite the file, otherwise create new file.
Write only mode
 1 // opening binary file in write only mode
 2 f = fopen("text.jpg", "wb");

ab mode

A mode ab is write only mode for binary file which allows to append file and place cursor at the end of file. If file exist, it place cursor at the end of file, otherwise create new file and write from the beginning of file.
Write only mode
 1 // opening binary file in write only mode
 2 f = fopen("text.jpg", "ab");

rb+ mode

A mode rb+ is read write mode for the binary file which allows to read write operation and place cursor at the beginning of the file. It open file only if file exist.
Read write mode
 1 // opening binary file in read write mode
 2 f = fopen("text.jpg", "rb+");

wb+ mode

A mode wb+ is read write mode for the binary file which allows to read and write operation and place cursor at the beginning of the file. If file exist, it overwrite the file, otherwise create new file.
Read write mode
 1 // opening binary file in read write mode
 2 f = fopen("text.jpg", "wb+");

ab+ mode

A mode rb+ is read write mode for the binary file which allows to append file and place cursor at the end of file. If file exist, it place cursor at the end of file, otherwise create new file and place cursor at the beginning of file.
Read write mode
 1 // opening binary file in read write mode
 2 f = fopen("text.jpg", "ab+");
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us