Simvik

Length of a string

Find where a piece of text ends. An easy embedded C problem (Arrays and text), run and graded in the browser.

easy · Arrays and text · strings

Text in C is an array of characters with a special character of value 0 marking the end. That marker is written '\0'.

Return the number of characters in text, not counting the marker.

Starter code

int text_length(const char text[]) {
  return 0;
}

Example tests

A word

printf("%d\n", text_length("hello"));

Expected output:

5

Empty text

printf("%d\n", text_length(""));

Expected output:

0

Learn it first

  • Arrays and text · Many values under one name, looping over them safely, and strings.

More Arrays and text problems