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:
5Empty text
printf("%d\n", text_length(""));Expected output:
0Learn it first
- Arrays and text · Many values under one name, looping over them safely, and strings.
More Arrays and text problems
- Sum an array · Visit every element with a loop.
- Largest element · Track the best value seen so far.
- Count readings above a threshold · Count the elements that pass a test.
- Fill an array · Write to the elements of an array.
- Find a value · Search an array and report where a value is.
- Average of readings · Combine a loop with integer division.
- Count a character · Loop over text and count matches.