Running order issues for printf and scanf under Eclipse

Source: Internet
Author: User

Running order issues for printf and scanf under Eclipse

Eclipse Yuto 2011-12-25 662 Browse to review

When writing a C language, the runtime found that scanf than printf first executed, in the Internet to find a bit of information, the original is the output buffer problem. There are two workarounds, first, the buffer is empty, that is, there is no buffer, and second, after each printf execution, the buffer is forced. Here's how:

    1. Add: Setvbuf (stdout,null,_ionbf,0) before printf, and set the buffer to null.

    2. After each sentence printf is added: Fflush (stdout);

The test code is as follows:

1. Added setvbuf (stdout,null,_ionbf,0);

/* * MAIN.C * * Created on:2015 January 29 * Author:qiang */#include <stdio.h>int Main () {int i = 3; SETVBUF (std out,null,_ionbf,0); printf ("hello\n"); scanf ("%i", &i); printf ("You entered%i", i); return 0;}

2 Add fflush (stdout);

/* * MAIN.C * * Created on:2015 January 29 * Author:qiang */#include <stdio.h>int Main () {int i = 3; printf ("Hel Lo\n "); Fflush (stdout); scanf ("%i", &i); printf ("You entered%i\n", i); Fflush (stdout);  scanf ("%i", &i); return 0;}

Running order issues for printf and scanf under Eclipse

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.