统计一个行文字大小写字母、空格、数字及其他

作者在 2012-10-29 15:08:34 发布以下内容
//:输入一个字符串,统计大写字母,小写字母,空格,数字以及其他个数
#include <stdio.h>

const int N = 100;

int main(){
    char *p, string[N];
    int uplet, lowlet, space, digit, other;

    uplet = lowlet = space = digit = other = 0;

    printf("输入字符串:");
    gets(string);
    p = string;

    while(*p!=''){
        if(*p>='A' && *p<='Z'){
            uplet++;
        }else if(*p>='a' && *p<='z'){
            lowlet++;
        }else if(' '==*p){
            space++;
        }else if(*p>='0' && *p<='9'){
            digit++;
        }else{
            other++;
        }
        p++;
    }//while
    
    printf("uplet = %d, lowlet = %d, space = %d, digit = %d, other = %dn", uplet, lowlet, space, digit, other);

    return 0;
}
 
基础编程 | 阅读 1329 次
文章评论,共0条
游客请输入验证码
浏览19228次
文章归档