typestar

Manual strlen in C

Walks to the terminating zero byte, which is all a C string is.

size_t my_strlen(const char *s) {
    const char *p = s;
    while (*p)
        p++;
    return (size_t)(p - s);
}

Keywords and builtins used here

The run, in numbers

Lines
6
Characters to type
94
Tokens
36
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 24 seconds.

Type this snippet

Step 4 of 5 in Arrays & strings, step 25 of 35 in Language basics.

← Previous Next →