输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数
输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数。 #include
int letter,digit,space,others; void main()
{
void count(char[]);
char text[80];
printf("Please ,,,,, string:\n");
gets(text);
printf("string:\n");
puts(text);
letter=0;
digit=0;
space=0;
others=0;
count(text);
printf("letter:%d,digit:%d,space:%d,others:%d\n",letter,digit,space,others);
}
void count(char str[])
{
int i;
for(i=0;str[i]!='\0';i++)
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
letter++;
else if(str[i]>='0'&&str[i]<='9')
digit++;
else if(str[i]==32)
space++;
else
others++;
}