_c language based on the use of C-language fflush () function

Source: Internet
Author: User
Tags stdin
Fflush is used to empty the buffer stream, although it is generally not felt, but the default printf is buffered output. Fflush (stdout), so that stdout empty, will immediately output all the contents in the buffer. The example of Fflush (stdout) may not be obvious, but it is obvious to stdin. The following statement: int a,c; scanf ("%d", &a); C=getchar (); Input: 12 (carriage return) so a=12, c= ' \ n ' and: int a,c; scanf ("%d", &a); Fflush (stdin); C=getchar (); Input: 12 (Enter) so a=12, C temporarily did not get the input value, but also need to enter C, because the GetChar is also buffer input, ' \ n ' Ben is still in the buffer, but was emptied. In addition, Fflush cannot be used to redirect input streams. Fflush (stdin) refreshes the standard input buffer and discards the contents of the input buffer
Fflush (STDOUT) refreshes the standard output buffer and prints the contents of the output buffer to the standard output device

Fflush (STDOUT)//What effect does this sentence play??? the function of Fflush () is to write the contents of the output buffer to the file to which the pointer points, or to clear the output buffer if the parentheses are pointers to open files. The stdout here is the system-defined standard output file pointer, which, by default, refers to the screen, where the contents of the buffer are written to the screen. But there is nothing in the code to see the buffer, so it doesn't really work.

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.