用c语言编程实现:输入一行文字,找出其中大写字母、小写字母、空格、数字以及其他字符各有多少。
时间: 2024-05-14 19:18:52 浏览: 24
以下是用C语言编写的实现代码:
```c
#include <stdio.h>
#include <ctype.h>
int main()
{
char str[100];
int i, uppercase, lowercase, digits, space, other;
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
i = uppercase = lowercase = digits = space = other = 0;
while (str[i] != '\0')
{
if (isupper(str[i]))
uppercase++;
else if (islower(str[i]))
lowercase++;
else if (isdigit(str[i]))
digits++;
else if (isspace(str[i]))
space++;
else
other++;
i++;
}
printf("Uppercase letters: %d\n", uppercase);
printf("Lowercase letters: %d\n", lowercase);
printf("Digits: %d\n", digits);
printf("Spaces: %d\n", space);
printf("Other characters: %d\n", other);
return 0;
}
```
运行程序后,输入一行文字,程序将会输出该行文字中大写字母、小写字母、空格、数字以及其他字符的个数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)