Kodewick
Start learning →
Starter←→0 / 50

Length without strlen

#043Starters[n] != '\0'4 min

A C string has a hidden '\0' at the end that means "stop here". Without strlen, write your own my_strlen(s): count from the start, stop at '\0', and return the count. "hello" is 5, a space counts as a character, and the empty string "" is 0.

Examples
my_strlen("hello")→5
my_strlen("")→0
my_strlen("a b c")→5
The functionint my_strlen(const char *s)
main.c
int my_strlen(const char *s) {
    int n = 0;
    // your code here: until you reach '\0', add 1 to n
    return n;
}
Ctrl + Enter runs too
Result

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