我尝试运行此代码:
printf("Enter a character.");
printf("\n");
do {
ch = getch();
system("cls");
putchar(ch);
} while(ch != '.');
以上代码在 Codeblocks 上运行良好,但在 Eclipse IDE 上不起作用。事实上,printf
循环之前的 do while
语句不起作用,但如果我禁用 do while
语句,printf 语句在 eclipse 上运行良好。你能解释一下为什么会这样吗?
答案 0 :(得分:1)
也许试试这个?
printf("Enter a character.\n");
fflush(stdout);
do {
ch = getch();
system("cls");
putchar(ch);
} while(ch != '.');
我认为这是因为您的输出缓冲区 (printf) 未刷新。