basics · beginner · ~15 min
Bound a scan so a missing NUL can't run off the end.
Implement int safe_strlen(const char *s, int max) returning the length of s but scanning at most max bytes (like strnlen).
int safe_strlen(const char *s, int max) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.