统计字符个数

来源:互联网 发布:文件查重软件 编辑:程序博客网 时间:2024/06/03 20:36
问题及代码:
#include <stdio.h>int main(){    int letter=0,number=0,space=0,other=0,e;    e = getchar();    while(e!='\n')    {        if ((e>='a'&&e<='z')||(e>='A'&&e<='Z'))            letter++;        else if (e>='0'&&e<='9')        {            number++;        }        else if(e==32)        {            space++;        }        else            other++;        e = getchar();    }    printf("%d %d %d %d",letter,number,space,other);    return 0;}


 

运行结果:

 

 

 

心得:getchar()的用法

0 0