ホームページ  >  記事  >  データベース  >  输入一行字符,分别统计出其中英文,空格,数字和其他字符的个数

输入一行字符,分别统计出其中英文,空格,数字和其他字符的个数

WBOY
WBOYオリジナル
2016-06-07 16:01:151897ブラウズ

int c = 0, space = 0, num = 0, other = 0; char s[] = djwiJFIW 123@#$!%; // scanf(%s, s); char *str = s; while (*str != \0) { if ((*str = A *str = Z) || (*str = a *str = z)) { c++; }else if (*str == ){ space++; }else if (*str = 0 *str = 9){

int c = 0, space = 0, num = 0, other = 0;

char s[] = "djwiJFIW 123@#$!%";

// scanf("%s", s);

char *str = s;

while (*str != '\0') {

if ((*str >= 'A' && *str = 'a' && *str

c++;

}else if (*str == ' '){

space++;

}else if (*str >= '0' && *str

num++;

}else{

other++;

}

str++;

printf("%c ", *str);

}

printf("英文,空格,数字和其他字符的个数分别为: %d,%d,%d,%d\n", c, space, num, other);

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。