Newer
Older
2023-Haruto / count.c
@”2022-Araki” ”2022-Araki” on 17 Nov 557 bytes ggggg
#include <stdio.h>

int count_char_occurrences(const char *input_str, char target_char) {
    int count = 0;
    
    while (*input_str) {
        if (*input_str == target_char) {
            count++;
        }
        input_str++;
    }
    
    return count;
}

int main() {
    const char *input_string = "Hello, World!";
    char target_character = 'l';
    
    int result = count_char_occurrences(input_string, target_character);
    
    printf("The character '%c' appears %d times in the given string.\n", target_character, result);

    return 0;
}