统计字母,数字,空格的个数

来源:互联网 发布:windows vista系统重装 编辑:程序博客网 时间:2024/05/19 23:23
//统计一个字符串中字母,数字,空格的个数#include <stdio.h>#include <string>#include <iostream>using namespace std;int main(){char *str = (char *)malloc(50*sizeof(char));printf("please input some characters:");gets(str);int alpha=0,num=0,upper=0,lower=0,space=0;char *s = str;int tag = 0;for(int i=0;i<strlen(str);i++){if(isalpha((int)(tag=*(s+i)))){alpha++;if(isupper(tag)){upper++;}else{lower++;}}else if(isdigit(tag)){num++;}else if(isspace(tag)){space++;}}printf("alpha is %d\n",alpha);printf("upper is %d\n",upper);printf("lower is %d\n",lower);printf("num is %d\n",num);printf("space is %d\n",space);system("pause");return 0;}
                                             
0 0
原创粉丝点击