C. Reading and Writing files

Source: Internet
Author: User

1. open the file:

Function prototype: file * fopen (const char * path, const char * mode); Return Value: After the file is successfully opened, the file pointer pointing to the stream will be returned. If the file fails to be opened, null is returned and the error code is stored in errno. Parameter description: the path string contains the path and file name of the file to be opened. The mode string represents the stream format. Mode has the following character strings: R opens a file in read-only mode and the file must exist. R + can open a file in read/write mode. The file must exist. RB + open a binary file to read and write data. The file must exist. RW + read/write opens a text file, allowing reading and writing. W. Open and write only the file. If the file exists, the file length is 0, indicating that the file content will disappear. 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 to zero, that is, the file content disappears. If the file does not exist, the file is created. A. Open and write-only files as an attachment. If the file does not exist, the file will be created. If the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained. (The EOF is retained) A + opens readable and writable files by appending them. If the file does not exist, the file will be created. If the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained. (The original EOF is not retained) WB only writes to open or create a new binary file; only data can be written. WB + enables read/write operations or creates a binary file, allowing read and write operations. Open a binary file through AB + read/write, and allow you to read or append data to the end of the file. At + open a file named string, and a indicates append, which means that the existing content of the original file is written at the time of writing, instead of overwriting from the beginning, t indicates that the type of the opened file is a text file, and the + number indicates that the file can be read or written. PS: Before reading and writing a file, open the file first.

2. Write files:

 

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.