Linux exercises (read)

Source: Internet
Author: User
# Include <unistd. h> # include <stdlib. h> int main () {char buffer [128]; int nread; nread = read (0, buffer, 128); If (nread =-1) write (2, "A read error has occurred \ n", 26); If (write (1, buffer, nread ))! = Nread) write (2, "A write error has occurred \ n", 27); exit (0 );}

Function prototype:

# Include <unistd. h>

Size_t read (INT Fildes, const void * Buf, size_t nbytes );

 

Read () parameter 1: Same as write ()

Parameter 2: Read data

Parameter 3: size of the read data

 

Return Value:

Normally, the returned data size is nbytes.

If the return value is 0, no data is read, which may reach the end of the file.

-1 indicates an error occurred.

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.