Added modes for file handling in index.md (#21902)

Added different modes that can be used and their description under "The Real Deal" Section.
pull/22707/head^2
Chase 2018-11-17 23:44:58 +05:30 committed by Christopher McCormack
parent eab6e7af01
commit 76f416935b
1 changed files with 26 additions and 0 deletions

View File

@ -168,6 +168,32 @@ The above methods only worked for the most basic of cases. If you wanted to do
To accomplish this, you will use a function called `fopen`. This function takes two string parameters, the first being the file name and the second being the mode.
Mode is basically permissions, so `r` for read, `w` for write, `a` for append. You can also combine them, so `rw` would mean you could read and write to the file. There are more modes, but these are the most used.
There are a number of modes that can be used for file handling.
**"r"** **-** **Open file for reading**
**rb** **-** **Open file for reading in binary mode**
**w** **-** **Open file for writing**
**wb** **-** **Open file for writing in binary mode**
**a** **-** **Open file for appending**
**ab** **-** **Open file for appending in binary mode**
**r+** **-** **Open file for both reading and writing**
**rb+** **-** **Open file for both reading and writing in binary mode**
**w+** **-** **Open file for both writing and reading**
**wb+** **-** **Open file for both writing and reading in binary mode**
**a+** **-** **Open file for both reading and appending**
**ab+** **-** **Open file for both reading and appending in binary mode**
After you have a `FILE` pointer, you can use basically the same IO commands you would've used, except that you have to prefix them with `f` and the first argument will be the file pointer.
For example, `printf`'s file version is `fprintf`.