Multiple Modes in fopen()

Modes parameter in fopen()

Created: 2022-07-10
Tags: #fleeting


Abstract:

  • Text Mode
  • Binary Mode

fopen("file_path", "mode");

Text Mode

r+ -> READING and WRITING
-> If file NOT exist, then fopen() returns NULL

w+ -> READING and WRITING
-> if file EXISTS, then contents overwritten
-> if file NOT exist, will be created

a+ -> APPENDING and READING
-> if file NOT exist, will be created

Binary Mode

rb+ -> READING and WRITING in binary mode
-> If file NOT exist, then fopen() returns NULL

wb+ -> READING and WRITING in binary mode
-> if file EXISTS, then contents overwritten
-> if file NOT exist, will be created

ab+ -> APPENDING and WRITING in binary mode
-> if file NOT exist, will be created

References