使用getchar() 来读取Console输入字符,如何结束输入?

uplyh uplyh 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下的一段代码在console里计算输入的行数, 如何输入才能使程序结束呢? 我在 win7 console里输入,却总在while循环里出不去,请大家帮忙看看,帮忙找个技术输入的方法,谢谢阿!

#include <stdio.h>
#include <stdlib.h>

int main()
{

char c;
int lineCount=0;
printf("Please begin to input:\n");
while((c=getchar())!=EOF)
{
if(c=='\n')
{
++lineCount;
}
if(c=='\r')
break;

}
printf("\nThe total lines are : %d",lineCount);


return 0;
}
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
uplyh
C语言 70,040 成员 243,237 内容