开发者

Why does Eclipse fail on this scanf() command when the Command Prompt executes it fine?

I'm new to C. Here's my code:

/* Using scanf() */
#include <stdio.h>

int main(void) {
    int iDec1, iDec2, iDec3;
    printf("Enter three decimals:\n");
    scanf("%d,%d,%d", &iDec1, &iDec2, &iDec3);
    printf("Your decimals are %d, %d and %d.", iDec1, iDec2, iDec3);
    return 0;
}

It works in the Command Prompt, but when I run it through Eclipse it doesn't do anything. After hitting stop, this appears in the Console output:

Enter three decimals

Your decimals are 3, 2147344384 and 2147344384.

What 开发者_高级运维the...? How come it works fine outside Eclipse but not inside Eclipse?


So, this thread might help you out. Yes, it's for Java, not C, but the last post on this thread outlines how to get input to work in eclipse console. This may just come down to how you run your program.

If the info in the link doesn't help, please post the steps you take to execute your program (which menu options you use etc. Also post eclipse version). I'll try to replicate.


fflush(stdout); did the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜