您的位置:首页 > 其它

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

2014-07-17 11:45 323 查看
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'){
num++;
}else{
other++;
}
str++;
printf("%c ", *str);

}
printf("英文,空格,数字和其他字符的个数分别为: %d,%d,%d,%d\n", c, space, num, other);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐