The use of the Fflush () function

Source: Internet
Author: User
Tags flush stdin
FF (stdin) refreshes the standard input buffer and discards anything in the input buffer.

Fflush (STDOUT) refreshes the standard output buffer and prints the output buffer to the standard output device.

When the scanf () function receives input data, it ends the input of one data in the following cases: (not to end the scanf function, the scanf function only has data in each data field and ends with a carriage return).
① the space, "enter", "Jump" key.
② to the end of the width.
③ in the event of illegal input.
The keyboard buffer may have residual information problems.
The scanf () function should simply scan the stdin stream, the remaining information is in stdin
The solution is to add a fflush (stdin) after the scanf () function

Third, the writing of the file will not be immediately the physical disk file read and write, but first write to the cache, when the contents of the cache to a certain extent before writing

FILE *fp=fopen ("A.txt", "w");
fprintf (FP, "abcdef");
Fflush (FP);

IV, int i;
for (i=0;i<10;i++)
{
printf ("%d", I);
Fflush (stdout);
Sleep (1);
}

When there is flush, the output of a number in a second when not flush is 10 seconds after the output of 10 characters

The result is of course the same: 0123456789

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.