fflush function and printf function "Go" in Linux

Source: Internet
Author: User

This article was reproduced from: http://blog.chinaunix.net/uid-30058258-id-5029847.html

printf is a row buffer function
The printf function is a standard function and will eventually be called to the system call function, and the printf function will fall into the write system function, but calling the write function requires satisfying some conditional pieces.
(1) Buffer full
(2) encountered \ r \ n
(3) Call the Fflush function to flush the buffer
(4) scanf reads the contents of the buffer
(5) The process or thread ending calling the printf function calls the Fflush function
The size of the detection buffer is 1024B.
Fflush function: Write out all the data not written in the file stream.

Function name: Fflush functions: Clear read-write buffer, need to immediately put the output buffer data to physically write when the header file: stdio.h prototype: int fflush (file *stream) where stream is the stream to be flushed
Fflush (stdin) refreshes the standard input buffer, discards the input buffer [non-standard]fflush (STDOUT) refreshes the standard output buffer, prints the output buffer to the standard output device printf ("...). "), with Fflush (stdout), to improve printing efficiency

Example for (i=1;i<=10;i++)
{
printf ("%d", I);
Sleep (1);
}
This is not output a number per second but 10 seconds after the output of 10 digits! The contents of the buffer are all output after printf plus fflush.

fflush function and printf function "Go" in Linux

Related Article

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.