The “r” mode mentioned above is one of the several modes in which we can open a file. These are mentioned below:
(i) “r” Searches the file. If the file exists, loads it in to memory and sets up a pointer which points to the first character in it. If the file doesn’t exist it returns NULL.
(ii) “w” Searches file if the file exists it contents are overwritten. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open file.
Operations possible - writing to the file.
(iii) “a” Searches file. If the file exists, loads it in to memory and sets up a pointer which points to the first character in it. If the file doesn’t exist a new file is created. Returns NULL, if unable to open file. Operations possible - Appending new contents at the end of file.
(iv) “r+” Searches file. If it exists, loads it in to memory and sets up a pointer which points to the first character in it. If file doesn’t exist it returns NULL.
Operations possible - reading existing contents, writing new contents, modifying existing contents of the file.
(v) “w+” Searches file. If the file exists, it contents are destroyed. It the file doesn’t exist a new file is created. Returns NULL if unable to open file. Operations possible - writing new contents, reading them back and modifying existing contents of the file. “a+” Searches if the file exists, loads it in to memory and sets up a pointer which points to the first character in it. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open file. Operations possible - reading existing contents, appending new contents to the end of file. Canot modify existing contents.
(i) “r” Searches the file. If the file exists, loads it in to memory and sets up a pointer which points to the first character in it. If the file doesn’t exist it returns NULL.
(ii) “w” Searches file if the file exists it contents are overwritten. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open file.
Operations possible - writing to the file.
(iii) “a” Searches file. If the file exists, loads it in to memory and sets up a pointer which points to the first character in it. If the file doesn’t exist a new file is created. Returns NULL, if unable to open file. Operations possible - Appending new contents at the end of file.
(iv) “r+” Searches file. If it exists, loads it in to memory and sets up a pointer which points to the first character in it. If file doesn’t exist it returns NULL.
Operations possible - reading existing contents, writing new contents, modifying existing contents of the file.
(v) “w+” Searches file. If the file exists, it contents are destroyed. It the file doesn’t exist a new file is created. Returns NULL if unable to open file. Operations possible - writing new contents, reading them back and modifying existing contents of the file. “a+” Searches if the file exists, loads it in to memory and sets up a pointer which points to the first character in it. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open file. Operations possible - reading existing contents, appending new contents to the end of file. Canot modify existing contents.