第十五周练习——统计字符串种类



Description
用指针编写一个程序,输入字符串后,统计其中各种字符的个数,输出其中大小写字母,数字,以及其他字符的个数。
主函数已经给出,请编写统计字符种类函数。
Input
一串字符串
Output
该字符串中大小写字母,数字,以及其他字符的个数,最后输出总字符串长度。
Sample Input**
I play LOL for 3 years.
Sample Output
4
12
1
6
23


代码:、

/* 
 Copyright (c) 2016,烟台大学计算机与控制工程学院 
 All Rights Reserved. 
 文件名称: 统计字符串种类
 作    者:胡寅生 
 完成日期:2016年12.13 
 版 本 号;v1.0 
*/  

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char str[100];
    gets(str);
    char *ptr=str;
    void fuction(char *);
    fuction(ptr);
    return 0;
}
void fuction(char *str)
{
    int a=0,b=0,c=0,d=0,i=0;
    while(str[i]!='\0')
    {
        if(str[i]>='A'&&str[i]<='Z')
            a++;
            else if(str[i]>='a'&&str[i]<='z')
                b++;
                else if( str[i]>='0'&&str[i]<='9')
                    c++;
                    else
                        d++;


        i++;
    }
    printf("%d\n%d\n%d\n%d\n%d\n",a,b,c,d,i);
}
运行结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值