用c语言输入一行字符,分别统计其中英文字母、空格和其他字符的个数,直到输入‘$’为止
时间: 2024-05-14 19:12:31 浏览: 70
```c
#include <stdio.h>
int main() {
char ch;
int letter = 0, space = 0, other = 0;
printf("请输入一行字符(以$结尾):\n");
while ((ch = getchar()) != '$') {
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
letter++;
} else if (ch == ' ') {
space++;
} else {
other++;
}
}
printf("字母个数:%d,空格个数:%d,其他字符个数:%d\n", letter, space, other);
return 0;
}
```
阅读全文
相关推荐




