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


#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);
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM