Name

strlen - calculate the length of a string

Library

libc.lib

Synopsis

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

Return values

The strlen function returns the number of characters that precede the terminating NULL character.

Detailed description

The strlen function computes the length of the string s.

Examples

#include <string.h>
#include <stdio.h>
int main()
{
    int ret;
    ret = strlen ("");
    printf("strlen of \"\" is %d\n",ret);
    ret = strlen ("a");
    printf("strlen of \"a\" is %d\n",ret);
    ret = strlen ("abcd");
    printf("strlen of \"abcd\" is %d\n",ret);   
    return 0;   
}

         

Output

strlen of "" is 0
strlen of "a" is 1
strlen of "abcd" is 4

         

Security considerations

The strlen function can be misused if the user passes a string that is not null terminated.

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top