What are different modes in which a file can be opened?

Questions by Tapas Mallick

Showing Answers 1 - 3 of 3 Answers

Pooja

  • Aug 26th, 2013
 

There are 6 main types of file opening mode:

1) "r". Open file for reading and file must exist;

2) "w" Open file for writing. If file does not exist it is created or if life already exist its content is erased.

3) "a" Open file for appending. It adds all information at the end of the file leaving old data untouched. If file does not exist it is created.

4) "r+" Open file for reading and writing and file must exist.

5) "w+" Open file for writing and reading. If file does not exist it is created or if life already exist its content is erased.

6) "a+" Open file for appending and reading. Again all new data is written at the end of the file old data leaving untouched. If file does not exist it is created. (You can read old data by moving pointer in file using fseek or rewind functions from stdio.h. But all writing operations will be done at the end of the file no matter how you change pointer)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions