Problems with scanf prior to printf in eclipse

Source: Internet
Author: User

Original: http://blog.csdn.net/linux_wgl/article/details/7430561

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. Added before printf: setvbuf (stdout,null,_ionbf,0);
      The set buffer is empty.
    2. After each sentence printf is added: Fflush (stdout);

The test code is as follows:

Method One:

#include <stdio.h>intMainvoid) {setvbuf (STDOUT,NULL,_IONBF,0); Charaa[ -]; printf ("Input:"); scanf ("%s", AA); printf ("output:%s", AA); return 0;}

Method Two:

int Main (void) {    char aa[];    printf ("input:");    Fflush (stdout);    scanf ("%s", aa);    printf ("output:%s", aa);    Fflush (stdout);     return 0 ;}


Problems with scanf prior to printf in 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.