Standard IO for UNIX advanced programming

Source: Internet
Author: User
Tags fread

C Standard IO---io with cache

Advantage:
With cache (merge system calls)
Disadvantages:
Low real-time availability
Type of cache:
Row cache: stdin stdout (buffer is size)
Full cache: File
No cache: stderr

1. Flow
The identity of the open file

2.FILE type
struct type:
File descriptor
The address of the buffer
Size of the cache


Error ID

3. Opening of the stream
fopen (3);

errno Global Variables
Defined macros:
/usr/include/asm-generic/errno-base.h
/usr/include/asm-generic/errno.h
Strerror (3);
Perror (3);


4. Stream operation (Read and write)
<1> bytes
Fgetc ();/fputc ();
GetChar ();/putchar ();
Getc ();/putc ();
<2> by row
Fgets ();/fputs ();
Gets ();/puts ();
<3> binary
Fread ();/fwirte ();
<4> formatting
FSCANF ();/fprintf ();
scanf ();/printf ();

5. Positioning of the stream
Fseek ();
Ftell ();
Rewind ();

6. Closing the stream
Fclose (3);

7. Refresh of the stream
Fflush (3);

8. Temporary files
Tmpnam ();//understanding
Tmpfile ();//Master

9.io efficiency
The discussion is not about the impact of cache size
Standard IO has created a buffer when calling fopen ()
Preferred choice:
Fgets ();/fputs ();
Fread ();/fwrite ();
10.
Setbuf ();
Setvbuf ();

Homework:
Add a string "uplooking" to the beginning of line 5th of a file

Standard IO for UNIX advanced programming

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.