c语言 11-5

1、

#include <stdio.h>

int count(const char *s, int key)
{
    int j = 0;
    while(*s)
    {
        if(*s == key)
            j++;
        s++;    
    }
    return j;
} 

int main(void)
{
    char str[128];
    printf("str: "); scanf("%s", str);
    
    printf("the number: %d\n", count(str, 'c'));
    return 0;
}

 

posted @ 2021-06-02 21:35  小鲨鱼2018  阅读(45)  评论(0编辑  收藏  举报