c语言统计英语字母,空格数字和其他字符的个数
时间: 2024-06-14 09:04:48 浏览: 18
以下是一个用C语言统计英语字母、空格、数字和其他字符个数的示例代码:
```c
#include <stdio.h>
void count(char str[]) {
int i = 0;
int letterCount = 0;
int digitCount = 0;
int spaceCount = 0;
int otherCount = 0;
while (str[i] != '\0') {
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) {
letterCount++;
} else if (str[i] >= '0' && str[i] <= '9') {
digitCount++;
} else if (str[i] == ' ') {
spaceCount++;
} else {
otherCount++;
}
i++;
}
printf("字母个数:%d\n", letterCount);
printf("数字个数:%d\n", digitCount);
printf("空格个数:%d\n", spaceCount);
printf("其他字符个数:%d\n", otherCount);
}
int main() {
char str[100];
printf("请输入字符串:");
gets(str);
count(str);
return 0;
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)