Kodewick
Start learning →
Mini challenge←→0 / 70

Locker code

#066Mini challengeStringsConditions6 min

Locker codes at the pool must be exactly 4 characters, all digits. Write valid_code(code): return true if it fits, otherwise false (an empty string is false too).

Examples
valid_code("2580")→True
valid_code("12a4")→False
The functionbool valid_code(const char *code)
main.c
#include <stdbool.h>
#include <string.h>

bool valid_code(const char *code) {
    // your code here: if the length is not 4, return false
    for (int i = 0; code[i] != '\0'; i++) {
        // your code here: if this character is not a digit, return false
    }
    return true;
}
Ctrl + Enter runs too
Result

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