Eclipse CDT中EOF信号输入的解决方法

使用Eclipse-cdt做开发的同学可能会遇到这样的,需要输入EOF作为结束标志结束输入,但是不知道怎么结束输入。在网上搜了一堆解决方法,都是说windows下使用 Ctrl+Z 做EOF信号,unix和linux下用 Ctrl+D 做EOF信号。自己在Eclipse-cdt中试一下,发现这招行不通。
例如调试和运行以下代码,使用 Ctrl+D 也是无法终止输入的。

#include <stdio.h>
/* count digits, white space, others */
main() {
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c - '0'];
else if (c == ' ' || c == '\n' || c == '\t')
++nwhite;
else
++nother;
printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n", nwhite, nother);
}

其实解决这个问题分为两步:
1. 依次代开“window“->"Perference"->"General"->"Keys",找到EOF的快捷键设置,设置为“Ctrl+D”,在“When”中设置为“I/O Console”,保存,OK~
2. 修改工程的Run配置,“Run”->“Run Configurations...”->“Main”,去掉Connect process input & output to a terminal,保存。

再次运行程序,输入数据结束后,使用"Ctrl+D"就可以结束输入了!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值