#include <stdio.h>

int main()
{
    char c;
    int letter = 0, digit = 0, space = 0, other = 0;

    printf("请输入若干字符,以*结束:\n");
    while ((c = getchar()) != '*') {
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
            letter++;
        } else if (c >= '0' && c <= '9') {
            digit++;
        } else if (c == ' ') {
            space++;
        } else {
            other++;
        }
    }

    printf("字母字符:%d,数字字符:%d,空格:%d,其他:%d\n", letter, digit, space, other);

    return 0;
}
C语言字符统计:字母、数字、空格和其他

原文地址: https://www.cveoy.top/t/topic/mSR2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录