#include <stdio.h>
int main(int argc, const char * argv[]) {
char c;
int letters=0,space=0,digit=0,others=0;
while((c=getchar())!='#')
{
if ((c>='a'&&c<='z')||(c>='A'&&c<='Z')) {
letters++;
}
else if(c==' ')
{
space++;
}
else if (c>='0'&&c<='9')
{
digit++;
}
else
{
others++;
}
}
printf("letters=%d,space=%d,digit=%d,others=%d\n",letters,space,digit,others);
return 0;
}
output:
123456qwerty \\\\
#
letters=6,space=1,digit=6,others=5
Program ended with exit code: 0
本文介绍了一个使用C语言实现的简单程序,该程序能够读取输入流中的字符,并将其分类为字母、空格、数字和其他类别,最后输出各类字符的数量。通过此程序,读者可以了解基本的字符判断和分类方法。
1万+

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



