统计一个字符串中字母,数字,空格和其他字符出现的次数

#include
#include
#include
void Fac_count_str(char* str)
{
char* p = str;
int letters = 0;
int blank = 0;
int dight = 0;
int others = 0;
while (*p)
{
if ((*p >= ‘a’ && *p <= ‘z’) || (*p >= ‘A’ && *p <= ‘Z’))
{
letters++;
}
else if (*p == ’ ')
{
blank++;
}
else if (*p >= ‘0’ && *p <= ‘9’)
{
dight++;
}
else {
others++;
}
p++;
}
printf(“letters=%d\n”, letters);
printf(“blank=%d\n”, blank);
printf(“dight=%d\n”, dight);
printf(“others=%d\n”, others);
}
int main()
{
char str[1024] = " ";
gets(str);
Fac_count_str(str);
system(“pause”);
return 0;
}

你可能感兴趣的:(统计一个字符串中字母,数字,空格和其他字符出现的次数)