strlen function
C
Function
Reference manual
@see man strlen
The strlen
function calculates the length of a null-terminated string by counting the number of characters in the string (excluding the null terminator). It returns the length of the string.
Syntax
size_t strlen(const char *str);
Parameters
str
: The input string for which the length is to be determined.
Return value
Returns the length of the string, which is the number of characters in the string.
Example
In the following example we use the strlen
function to count the number of characters in the string “Hello, World!” and we output it.
#include <stdio.h>
#include <string.h>
int main(void)
{
const char str[] = "Hello, World!";
size_t length = strlen(str);
printf("String length: %zu\n", length);
return (0);
}