Linux fread and fwrite

Source: Internet
Author: User

Linux fread and fwrite 1. The function is used to read and write a data block. 2. the call method is fread (buffer, size, count, fp), fwrite (buffer, size, count, fp), and 3. description (1) buffer: A pointer. For fread, It is the storage address for reading data. For fwrite, It is the address of the data to be output. (2) size: the number of bytes to read and write; (3) count: the number of size bytes to read and write data items; (4) fp: file type pointer. 4. example: 1. fread (& id, f) refers to reading the value in f into id, reading 1 byte each time, reading 10 times in total, or reading all the values in id, it will also be stopped less than 10 times. 2. fwrite (& id, f) is to read the value in id into f, read 1 byte each time, read 10 times in total or fread (& id, 10, 1, f) it is to read the value in the id into it, and read 10 bytes each time for a total of 1 read. The difference between fread and read: 1. fread is buffered, and read is not buffered. 2. fopen is defined in standard c, and open is defined in POSIX. 3. fread can read a structure. in linux/unix, there is no difference between reading binary data and common files. 4. fopen cannot specify the permission to create a file. open allows you to specify permissions. 5. fopen returns the pointer and open returns the file descriptor (integer ). 6. If any device in linux/unix is a file, you can use open or read.

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.