#include<stdio.h>
#include<stdlib.h>
#include<string.h>
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;
}
统计一个字符串中字母,数字,空格和其他字符出现的次数
最新推荐文章于 2024-02-23 15:09:53 发布