读书人

怎么改这个程序呢让它实现小弟我换行

发布时间: 2012-09-17 12:06:51 作者: rapoo

如何改这个程序呢,让它实现我换行输入时也把按的Enter键统计到other的数目里面,谢谢啦!
#include <stdio.h>
#include <ctype.h>
int main (void)
{char ch;
int lower=0;
int upper=0;
int other=0;
while ((ch=getchar())!='#')
{if(islower(ch))
l++;
else if (isupper(ch))
u++;
else o++;
}
printf("%d ,%d ,%d ",lower,upper,other);
return 0;
}

[解决办法]

C/C++ code
#include <stdio.h>#include <ctype.h>int main (void){char ch;int lower=0;int upper=0;int other=0;while ((ch=getchar())!='EOF'){    if (ch == '#')    {        break;    }    if(islower(ch))        lower++;    else if (isupper(ch))            upper++;    else other++;}printf("%d ,%d ,%d ",lower,upper,other);return 0;}
[解决办法]
在C语言中,或更精确地说成C标准函式库中,表示文件结束符(end of file)。
在while循环中以EOF作为文件结束标志,这种以EOF作为文件结束标志的文件,必须是文本文件。在文本文件中,数据都是以字符的ASCII代码值的形式存放。我们知道,ASCII代码值的范围是0~255,不可能出现-1,因此可以用EOF作为文件结束标志。

读书人网 >C语言

热点推荐