strlen() — Determine String Length

Format

#include <string.h>
size_t strlen(const char *string);

Language Level

ANSI

Threadsafe

Yes

Description

The strlen() function determines the length of string excluding the ending null character.

Return Value

The strlen() function returns the length of string.

Example

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] ));
}
/******************  If the input is the string  ***********************
*****************"How long is this string?", ******************
******************  then the expected output is:  *****************
 
Input string has a length of 24
*/

Related Information