#include <stdio.h>
#include <string.h>
//输入一串字符串,统计字符串数字、英文、空格、其他字符各有多少个
int main()
{
int len,digit=0,word=0,space=0,other=0;
char arr[20];
gets(arr);
len=strlen(arr);//查看arr中有多少个字符(strlen()是统计字符串中元素数量,函数包含在string.h头文件里)
for(int i=0;i<len;i++)
{
if((arr[i]>=’a’&&arr[i]<=’z’)||(arr[i]>=’A’&&arr[i]<=’Z’))//统计字母
word++;
else if(arr[i]>=’0’&&arr[i]<=’9′)//统计数字
digit++;
else if(arr[i]==’ ‘)//统计空格
space++;
else//统计其它
other++;
}
printf(“digit=%d,word=%d,space=%d,other=%d”,digit,word,space,other);
return 0;
}