Binary File Modes in C
During programming binary file can be opened for different purposes i.e. reading, writing or both. This is specified by using file modes. Different binary file modes in C programming are tabulated below:
Modes | Purpose |
---|---|
rb | Open binary file for reading only. The file must already exist. |
wb | Open binary file for writing only. If the file specified already exists, its contents will be destroyed. If it does not exist it will be created. |
ab | Open binary file for appending (i.e. adding data to the end of existing file). If it does not exist it will be created. |
rb+/r+b | Open binary file for both reading and writing. The file must already exist. |
wb+/w+b | Open binary file for both reading and writing. If the file exists, its content will be overwritten. If it does not exist it will be created. |
ab+/a+b | Open binary file for both reading and appending. If a file does not exist it will be created. |