strlen() — Determine string length
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C
POSIX.1 XPG4 XPG4.2 C99 Single UNIX Specification, Version 3 |
both |
Format
#include <string.h>
size_t strlen(const char *string);
General description
The strlen() built-in function determines the length of string pointed to by string, excluding the terminating NULL character.
Returned value
strlen() returns the length of string.
Example
CELEBS43
/* CELEBS43
This example determines the length of the string that is
passed to main.
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
if ( argc != 2 )
printf( "Usage: %s string\n", argv[0] );
else
printf( "Input string has a length of %i\n", strlen( argv[1] ));
}
Output
If the input is the string:
"How
long is this string?"
, then the expected output is: Input string has a length of 24