C language file operations: Detailed description of file opening Methods

Source: Internet
Author: User
Tags rewind

C language file operations: Detailed description of file opening Methods

Fopen Mode

R stands for the abbreviation of read, + stands for readable and writable, w stands for write, B stands for bit binary, t stands for text
R: open a read-only file. The file must exist.
R + open a readable and writable file, which must exist (The Write File here refers to overwrite the previous file
Rt open a read-only text file, which must exist
Rt + read/write open a text file, which can be read and written. The file must exist (The Write File here refers to overwrite the previous file
Rb only opens a binary file, which must exist
Rb + read/write open a text file, which can be read and written. The file must exist (The Write File here refers to overwrite the previous file

W open and write only files. If the file exists, the file length is cleared, that is, the file content disappears. If the file does not exist, the file is created.
W + open the readable and writable file. If the file exists, the file length is cleared, that is, the file content disappears. If the file does not exist, the file is created (the Read File here, you also need to use the rewind () function)
Wt open a text-only file. If the file exists, the file length is cleared, that is, the file content disappears. If the file does not exist, the file is created.
Wt + open a readable/Writable Text File. If the file exists, the file length is cleared, that is, the file content disappears. If the file does not exist, the file is created.
If wb is enabled, only binary files are written. If the file exists, the file length is cleared, that is, the file content disappears. If the file does not exist, the file is created.
Wb + opens a readable and writable file. If the file exists, the file length is cleared, that is, the file content disappears. If the file does not exist, the file is created.

A. Open the write-only file as an attachment. If the file does not exist, create a file. If the file exists, add data at the end of the file, that is, append the content.
A + opens a read/write file in the append mode. If the file does not exist, it creates a file. If the file exists, it writes data to the end of the file (the Read File here also needs to use the rewind () function, however, the rewind () function is not required for writing files. a is an append)
At: The append of binary data. If no value exists, it is created and can only be written.
At + read and write to open a text file and allow reading or appending data at the end of the text (the Read File here also requires the rewind () function, but the rewind () function is not required to write the file, a Is append)
The append of the AB binary data. If no value exists, it is created and can only be written.
AB + reads and writes to open a binary file. If the binary file does not exist, it is created. You can read or append data to the end of the text (the Read File here also needs to use the rewind () function, however, the rewind () function is not required for writing files. a is an append)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.