#include<stdio.h>
#include<ctype.h>
int main()
{
printf("请输入字符串:");
char cha; //字符串
int number = 0;//数字个数初始值
int ch = 0;//字母个数初始值
int other = 0;//其他符号个数初始值
while ((cha = getchar())!= '\n')//while((cha = getchar()) !=EOF)
{ //判断是否为数字
if (isdigit(cha)!=0)
{
number += 1;
}
//判断是否为字母
else if ( isalpha(cha)!=0)
{
ch += 1;
}
else
{
other += 1;
}
}
printf("字母个数:%d 数字个数:%d 其他符号个数:%d ",ch ,number, other);
return 0;
}
EOF可以输入多行字符(文本)
按 Ctrl+c结束输入
本文介绍了一个使用C语言编写的程序,该程序能够接收用户输入的一串字符,并统计出这串字符中数字、字母及其他符号的数量。通过使用标准输入输出库和字符处理库,程序能准确地对各种字符进行分类计数。

2263

被折叠的 条评论
为什么被折叠?



