Erick


私信TA

用户名:dotcpp0642224

访问量:187

签 名:

等  级
排  名 18643
经  验 698
参赛次数 0
文章发表 9
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:需要調用函數,而且此函數還需給出4個統計值,故需要使用指針,函數只能返回0個或一個值

注意事项:

参考代码:

#include<stdio.h>

 

void cnt_fun(char total[],int len_0,int *ch,int *num,int *sp,int *oth);

 

int main(void)

{

    char get[100];

    int cnt_let=0;

    int cnt_num=0;

    int cnt_spa=0;

    int cnt_oth=0;

    int c,len=0;

    int i;

     

    while((c=getchar())!='\n'&&c!=EOF){

        get[len++]=c;

    }

 

     

    cnt_fun(get,len,&cnt_let,&cnt_num,&cnt_spa,&cnt_oth);

 

    printf("%d %d %d %d",cnt_let,cnt_num,cnt_spa,cnt_oth);

     

    return 0;

}

 

void cnt_fun(char total[],int len_0,int* ch,int* num,int* sp,int* oth)

{

    int i;

    int a,b,c,d;

    for(i=0;i<len_0;i++){

        if(total[i]>='A'&&total[i]<='Z'||total[i]>='a'&&total[i]<='z'){

            (*ch)++;//此處注意++的運算等級高於*,故需要加括號,提升優先級

        } else if(total[i]>='0'&&total[i]<='9'){

            (*num)++;

        } else if(total[i]==' '){

            (*sp)++;

        } else {

            (*oth)++;

        }

    }  

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区