输入一个字符串,统计英文字母、空格、数字和其它字符的个数

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void check_count();
int main() {
    
    check_count();
    return 0;
}
void check_count() {
    int count_digit = 0, count_letter = 0, count_space = 0, count_other = 0;
    char c;
    printf("请输入一串字符!\n");
    while ((c = getchar()) != '\n') {
        if (c >= 'a' && c <= 'z' || c >= 'A' &&c <= 'Z') {
            count_letter++;
        }
        else if (c == ' ') {
            count_space++;
        }
        else if (c >= '0' && c <= '9') {
            count_digit++;
        }
        else {
            count_other++;
        }


    }
    printf("\n统计结果:\n英文字母=%d\n空格=%d\n整数=%d\n其他字符=%d\n\n", count_letter, count_space, count_digit, count_other);
}

 

posted @ 2022-04-13 17:20  蛋混小  阅读(1253)  评论(0)    收藏  举报