Name
strlen
- calculate the length of a string
Synopsis
1
2
3
#include <string.h>
size_t strlen(const char *s);
Description
The strlen()
function calculates the length of the string pointed
to by s
, excluding the terminating null byte (‘\0’). Note that
strlen()
stops counting characters as soon as it encounters a
null byte.
Example
1
2
3
4
5
6
7
#include <assert.h>
#include <string.h>
int main() {
char s[7] = "hello!";
assert(strlen(s) == 6);
}
Return Value
Upon completion, the strlen()
function returns the number of characters
in the string pointed to by s
.