Simvik

Implement strlen

Count the characters before the terminating NUL. An easy embedded C problem (Arrays and strings), run and graded in the browser.

easy · Arrays and strings · strings · libc

A C string is an array of characters that ends with a zero byte. Return the number of characters before that terminator.

Starter code

size_t my_strlen(const char *s) {
  // Count characters up to, but not including, the '\0'.
  return 0;
}

Example tests

A word

printf("%u\n", (unsigned)my_strlen("hello"));

Expected output:

5

Empty string

printf("%u\n", (unsigned)my_strlen(""));

Expected output:

0

Learn it first

  • Arrays and strings · Decay, bounds, safe copying, and parsing and formatting without the heap.

More Arrays and strings problems