一、运行结果;
二、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
//声明分类统计函数;
void statistics(char a[100]);
int main()
{
//初始化变量值;
char a[100] = { 0 };
//获取用户输入数据;
printf("请输入一串字符串:");
gets(a);
//输出结果;
printf("您输入的结果为:%s", a);
//换行;
printf("\n");
//调用函数;
statistics(a);
return 0;
}
//实现分类统计函数;
void statistics(char a[100])
{
//初始化变量值;
int i, letter = 0, space = 0, number = 0, others = 0;
//循环判断;
for (i = 0; a[i] != '\0'; i++)
{
//判断字母;
if ((a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= 'a' && a[i] <= 'z'))
{
//加1;
letter++;
}
else if (a[i] == ' ')
{
space++;
}
else if (a[i] >= '0' && a[i] <= '9')
{
number++;
}
else
{
others++;
}
}
//输出结果;
printf("您输入的字符串有%d个字母,%d个数字,%d个空格,%d个其他字符\n", letter, number, space, others);
}