演習 11-5

#include <stdio.h>
#include <string.h>

int str_chnum(const char *s, int c){

    int i, count = 0;

    for(i = 0; i < strlen(s); i++){
        if(c == *(s + i)) count++;
    }
    return count;
}

int main(){

    char s[256];

    printf("入力 : ");    scanf("%s", s);

    printf("cの個数は%d個です\n", str_chnum(s, 'c'));

    return 0;
}

0 件のコメント:

コメントを投稿