Usage of C language-based fflush () Functions

Source: Internet
Author: User

Fflush is used to clear the buffer stream. Although it is generally invisible, the default printf is used to buffer the output. Fflush (stdout), so that stdout is cleared, it will immediately output all content in the buffer. The fflush (stdout) example may not be obvious, but it is obvious to stdin. The following statement: int A, C; scanf ("% d", & A); C = getchar (); input: 12 (Press ENTER) then a = 12, C = '\ n' and: int A, C; scanf ("% d", & A); fflush (stdin); C = getchar (); input: 12 (Press ENTER) So A = 12, C does not get the input value for the moment, you need to enter C again, because getchar is also a buffer input, '\ n' is still in the buffer, but it is cleared. In addition, fflush cannot be used to redirect input streams. Fflush (stdin) refreshes the standard input buffer and discards the content in the input buffer.
Fflush (stdout) refreshes the standard output buffer and prints the output buffer to the standard output device.

Fflush (stdout); // What is the role of this sentence ??? --What is the role of fflush ()?: If a pointer is written to an opened file in parentheses, the content of the output buffer is written to the file pointed to by the pointer. Otherwise, the output buffer is cleared. Stdout is the standard output file pointer defined by the system. By default, it refers to the screen, that is, the buffer content is written to the screen. HoweverCodeI can't see what the buffer will do, so it does not actually do anything.

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.