使用getchar() 来读取Console输入字符,如何结束输入?
uplyh 2012-02-14 11:20:17 以下的一段代码在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;
}