代码: 全选
#include "stdio.h"
#include "ctype.h"
int main(int argc, char const *argv[])
{
int ch;
int upper_count, lower_count;
upper_count = lower_count = 0;
while ((ch = getchar()) != EOF) {
if (islower(ch) == 1) {
lower_count++;
} else if (isupper(ch) == 1) {
upper_count++;
} else {
continue;
}
}
printf("lowercase number: %5d, uppercase number: %5d\n", lower_count, upper_count);
return 0;
}
选择语句里的 islower(ch) == 1 为什么必须写成 islower(ch) 才对。
如果是小写,islower(ch) 返回是 1, 1 == 1,是真,结果没有执行选择语句。实在搞不懂。