Name
strlen
- calculate the length of a string
Synopsis
#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
#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
.