Kodewick
Start learning →
Basic←→0 / 70

Phone digits

#043BasicStringsConditions4 min

A friend's number came with dashes, spaces and brackets. Write count_digits(phone) to count only the characters from '0' to '9'; everything else is skipped. An empty string gives 0.

Examples
count_digits("138-0013-8000")→11
count_digits("")→0
The functionint count_digits(const char *phone)
main.c
int count_digits(const char *phone) {
    int n = 0;
    for (int i = 0; phone[i] != '\0'; i++) {
        // your code here: if it is between '0' and '9', add 1 to n
    }
    return n;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.