Scanf在Eclipse中的printf之前执行

问题描述 投票:1回答:1

我有以下简单的C语言代码:

#include <stdio.h>

int main(){
    printf("Give an integer:\n");
    int x;
    scanf("%d",&x);
    printf("10*%d=%d\n",x,10*x);

    return 0;
}

使用CodeBlocks IDE,它以正确的顺序执行,但是当我使用Eclipse IDE时,它会跳转到scanf命令,然后按需打印消息。谁能解释一下?

提前谢谢您

c eclipse printing ide scanf
1个回答
0
投票

通常stdout设置为行缓冲。显然,您的一个IDE将其设置为完全缓冲

您可以用fflush()强制打印以转储关联的缓冲区,例如

putchar('s');         // works in unbuffered stream
printf("omething\n"); // works in line buffered stream
fflush(stdout);       // works in fully buffered stream
© www.soinside.com 2019 - 2024. All rights reserved.