用C语言输入一串字符,分别统计其中英文字母,数字,空格和其他字符的个数
时间: 2023-11-23 16:05:16 浏览: 83
```c
#include<stdio.h>
#include<ctype.h>
int main()
{
char str[1000];
int i, alpha, digit, space, other;
alpha = digit = space = other = i = 0;
printf("Enter a string: ");
gets(str);
while(str[i] != '\0')
{
if(isalpha(str[i]))
{
alpha++;
}
else if(isdigit(str[i]))
{
digit++;
}
else if(str[i] == ' ')
{
space++;
}
else
{
other++;
}
i++;
}
printf("Number of alphabets: %d\n", alpha);
printf("Number of digits: %d\n", digit);
printf("Number of spaces: %d\n", space);
printf("Number of other characters: %d\n", other);
return 0;
}
```
阅读全文