Use of Basic Input/Output Functions

Source: Internet
Author: User

Fread reads nmemb elements from the file stream and writes them to the memory directed by PTR. The size of each element is size byte.

Fwrite reads nmemb elements from the memory directed by PTR and writes them to the file stream. Each element has size bytes.

All file read/write functions start to read and write from the current read/write point of the file. After reading, the current read/write point automatically moves the size * nmemb byte.

 

Gets () ignores '\ n'. If the program is executed, press enter, and the string stores' \ 0 '. If an error occurs or ends at the end of the file, null is returned.

Puts () will replace '\ 0' with \ N output. In case of an error, EOF is returned.

Fgets () returns the first address of the array, '\ n' is also saved, and an' \ 0' is added. If the object ends, null is returned. If an error occurs or ends at the end of the file, null is returned.

Fputs does not automatically add line breaks at the end of a row. In case of an error, EOF is returned.

Note: When reading strings from a file, '\ 0' D is automatically added to the end.

 

Writes formatted strings starting with F to the file stream, or reads formatted strings from the file stream.

Writes formatted strings starting with S to STR, or reads formatted strings from Str.

If you write a function, the number of written characters (not including '\ 0') is returned. If an error occurs, a negative number is returned.

For a READ function, the number of matched values is returned. If an error occurs or the end of the file is reached, EOF is returned.

Note: For read functions, spaces are ignored when matching strings, and '\ 0' is added at the end '.

 

The read and write functions are called in Linux and are only used in Linux. Not buffered.

Note:

For pipelines, the read return value can be in the following three situations:

1. Reading is normal. The number of characters read is returned.

2. The peer write end is disabled, and read returns 0.

3. Close your own read end. If a read error occurs,-1 is returned.

Note: When reading data to an Array Using read, '\ 0' is not automatically added to the end!

Use of Basic Input/Output Functions

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.