刘华世的官方博客

统计各种字符个数

#include <stdio.h>
#include <conio.h>

 
int main(int argc, char * argv[])
{

    char ch;
    int letters = 0, space = 0, digit = 0, others = 0;
    printf("请输入一组字符串:\n");
    while((ch=getchar())!='\n')
    {
        if(ch>'a' && ch < 'z' || ch >'A' && ch< 'Z')
            letters++;
        else if(ch == ' ')
            space++;
        else if(ch>='0' && ch<='9')
            digit++;
        else
            others++;
        
    }
    printf("英文个数为:%d,空格为:%d,数字为:%d,其他字符:%d", letters, space, digit, others);
    getch();

    return 0;
}
posted @ 2012-10-29 22:58  pythonschool  阅读(471)  评论(0编辑  收藏  举报
刘华世的官方博客