c语言编程从键盘输入一行字符串,统计其中英文字符、数字、空格和其他字符的个数。
时间: 2024-01-09 09:48:50 浏览: 29
```
#include <stdio.h>
#include <ctype.h>
int main()
{
char str[100];
int i, alpha, digit, space, other;
alpha = digit = space = other = 0;
printf("请输入一个字符串:");
fgets(str, 100, stdin);
for (i = 0; str[i] != '\0'; i++)
{
if (isalpha(str[i]))
{
alpha++;
}
else if (isdigit(str[i]))
{
digit++;
}
else if (isspace(str[i]))
{
space++;
}
else
{
other++;
}
}
printf("字符串中英文字符的个数为:%d\n", alpha);
printf("字符串中数字的个数为:%d\n", digit);
printf("字符串中空格的个数为:%d\n", space);
printf("字符串中其他字符的个数为:%d\n", other);
return 0;
}
```