basics · beginner · ~15 min
Verify a buffer is NUL-terminated before treating it as a string.
Implement int has_nul_within(const char *buf, int n) returning 1 if a NUL byte appears within the first n bytes of buf, else 0. This is how you check a buffer is a safe C string before using it.
int has_nul_within(const char *buf, int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.